Skip to content

Commit

Permalink
🍻 Add params.twitter.enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Ice-Hazymoon committed Nov 7, 2022
1 parent 08886ca commit abadd6c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ params:
minStars: 5

twitter:
enabled: true
rsshub: "https://rsshub.rssforever.com"
id: ""
imageProcessing: true
Expand Down
1 change: 1 addition & 0 deletions exampleSite/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ params:
# Twitter 页面设置
# tweet page
twitter:
enabled: true
rsshub: "https://rsshub.rssforever.com" # rsshub url, see https://github.com/DIYgod/RSSHub
id: "GenshinImpact" # Twitter ID
# 如果为 true,Hugo 将下载图片和视频并进行优化,如果你在中国大陆地区,请谨慎启用这个选项
Expand Down
7 changes: 6 additions & 1 deletion layouts/_default/twitter.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{{- $Site := .Site -}}
<div class="page-twitter relative py-8">
<div class="mx-6 md:mx-10">
{{- if $twitterConfig.enabled -}}
<div class="mb-10 inline-flex items-end pb-3 text-3xl">
<div class="mr-4 inline-flex items-center leading-none">
<i class="eva eva-twitter-outline mr-2"></i>
Expand All @@ -24,7 +25,8 @@

<div id="twitter">
{{- if $twitterConfig.id -}}
{{- $twitterData := getJSON (print "https://api.rss2json.com/v1/api.json?rss_url=" $twitterConfig.rsshub "/twitter/user/" $twitterConfig.id) -}}
{{- $apiurl := (print "https://api.rss2json.com/v1/api.json?" (querify "rss_url" (print $twitterConfig.rsshub "/twitter/user/" $twitterConfig.id))) -}}
{{- $twitterData := getJSON $apiurl -}}
{{- range (index $twitterData "items") -}}
{{- $pubDate := dateFormat (T "date.d_m_h_s") .pubDate -}}
{{- $content := (trim (replaceRE "<br>" "\n" (replaceRE "<video(.+?)</video>|<img(.+?)>" "" .content)) "\n") | safeHTML -}}
Expand Down Expand Up @@ -201,6 +203,9 @@
<div class=" text-xl">ERROR: {{- T "twitter.config" -}}</div>
{{- end -}}
</div>
{{- else -}}
<div class=" text-xl">Twitter page is not enabled</div>
{{- end -}}
</div>
</div>
{{- end -}}

0 comments on commit abadd6c

Please sign in to comment.