Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix jump to comments button present when comments are disabled #3

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions exampleSite/content/posts/rich-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ and no-JS versions of various social media embeds.

---

## Twitter Shortcode
## X(Twitter) Shortcode

{{< tweet user="SanDiegoZoo" id="1453110110599868418" >}}
{{< x user="SanDiegoZoo" id="1453110110599868418" >}}

<br>

Expand Down
24 changes: 21 additions & 3 deletions exampleSite/hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,29 @@ params:
twitter: 'Your Twitter username'
github: 'Your GitHub username'
linkedin: 'Your LinkedIn username'
disableShareByType:
- not-exist

share:
disabled: false
disableByType: # content type
- not-exist
platforms: # available inherit platform: [redidit, x, facebook, google, telegram]
- name: reddit # inherit platform just need the name
- name: x
- name: facebook
- name: google
# - name: telegram # disable the inherit platform
- name: Linkedin # this is a custom platform
url: "https://www.linkedin.com/shareArticle?url=%s&title=%s" # args(Permalink, Title)
- name: WhatsApp
url: "https://wa.me/?text=%s %s"
connect:
platforms: # available inherit platform: [github, x, linkedin]
- github
- x
- linkedin

articleMetadata:
position: header # Can be either header, sidebar or none.
position: header # Can be either [header, sidebar, none].

# Table of contents
toc:
Expand Down
5 changes: 1 addition & 4 deletions exampleSite/hugo_stats.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
"dark:bg-neutral-900",
"dark:bg-neutral-900/50",
"dark:bg-neutral-900/70",
"dark:bg-neutral-900/80",
"dark:bg-sky-400/90",
"dark:bg-sky-800/50",
"dark:bg-sky-950/30",
Expand Down Expand Up @@ -393,7 +392,6 @@
"lg:gap-8",
"lg:grid-cols-3",
"lg:h-12",
"lg:mb-12",
"lg:mb-4",
"lg:mb-8",
"lg:min-h-screen",
Expand Down Expand Up @@ -430,7 +428,6 @@
"md:hidden",
"md:items-center",
"md:mb-4",
"md:mb-8",
"md:p-3",
"md:px-2",
"md:px-8",
Expand Down Expand Up @@ -668,10 +665,10 @@
"toc",
"toc-toggle",
"toggle-sidebar",
"twitter-shortcode",
"unordered-list",
"vagus-elidunt",
"vimeo-shortcode",
"xtwitter-shortcode",
"youtube-privacy-enhanced-shortcode"
]
}
Expand Down
10 changes: 8 additions & 2 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- define "main" -}}
{{- $enableComments := and (not .Site.Params.comment.disabled) (not (in .Site.Params.comment.disableByType .Type)) -}}
{{- $metadataPosition := lower (default "header" .Site.Params.articleMetadata.position) -}}

<div class="container mt-1 mx-auto px-2 py-2 md:px-2 md:py-4 lg:px-4 lg:py-8 min-h-screen">
Expand Down Expand Up @@ -43,6 +44,7 @@ <h1 class="fluidity-page-title text-4xl group mb-2 md:mb-4 lg:mb-8">
{{- partial "article-metadata" . -}}
{{- end -}}


<div
class="sticky top-4 rounded-xl p-4
relative overflow-hidden
Expand All @@ -54,7 +56,10 @@ <h1 class="fluidity-page-title text-4xl group mb-2 md:mb-4 lg:mb-8">
transition-all duration-300 ease-out">
{{- $enableToc := and (gt .WordCount 400) (and (not (eq .Params.toc false)) (not .Site.Params.toc.disabled)) -}}
{{- $enableToc = not (eq .TableOfContents "<nav id=\"TableOfContents\"></nav>") -}}
{{- $enableShare := not (in .Site.Params.social.disableShareByType .Type) -}}
{{- $enableShare := false -}}
{{ if and (isset .Site.Params "social") (isset .Site.Params.social "share") }}
{{ $enableShare = and (not .Site.Params.social.share.disabled) (not (in .Site.Params.social.share.disableByType .Type)) }}
{{ end }}

{{- if and $enableToc -}}
<div class="relative">
Expand Down Expand Up @@ -93,6 +98,7 @@ <h1 class="fluidity-page-title text-4xl group mb-2 md:mb-4 lg:mb-8">
<span>{{ i18n "backToTop" | default "Back to Top" | title }}</span>
</button>

{{- if $enableComments }}
<button
onclick="document.getElementById('comments').scrollIntoView({behavior: 'smooth'})"
class="group inline-flex items-center gap-1 py-1.5 rounded-lg cursor-pointer
Expand All @@ -106,6 +112,7 @@ <h1 class="fluidity-page-title text-4xl group mb-2 md:mb-4 lg:mb-8">
</span>
<span>{{ i18n "jumpToComments" | default "Jump to Comments" | title }}</span>
</button>
{{- end }}

<button
id="toggle-sidebar"
Expand All @@ -129,7 +136,6 @@ <h1 class="fluidity-page-title text-4xl group mb-2 md:mb-4 lg:mb-8">
</div>

<aside id="article-aside" class="mt-4 lg:mt-12">
{{- $enableComments := and (not .Site.Params.comment.disabled) (not (in .Site.Params.comment.disableByType .Type)) -}}
{{- $enableRelated := and (not .Site.Params.relatedPosts.disabled) (not (in .Site.Params.relatedPosts.disableByType .Type)) (.Site.RegularPages.Related .) -}}
{{- $activeTab := "comments" -}}
{{- if not $enableComments -}}
Expand Down
31 changes: 2 additions & 29 deletions layouts/partials/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,8 @@ <h3 class="text-lg sm:text-xl font-semibold text-neutral-900 dark:text-neutral-5
{{- i18n "connect" | strings.Title -}}
</h3>
<ul class="space-y-2">
{{- partial "inline/footer/connect-item.html" (dict "icon" "rss" "title" "RSS Feed" "url" ("index.xml" | relURL)) -}}
{{- with .Site.Params.social.twitter -}}
{{- partial "inline/footer/connect-item.html" (dict "icon" "xcom" "title" "X.com" "url" (printf "https://x.com/%s" .)) -}}
{{- end -}}
{{- with .Site.Params.social.github -}}
{{- partial "inline/footer/connect-item.html" (dict "icon" "github" "title" "GitHub" "url" (printf "https://github.com/%s" .)) -}}
{{- end -}}
{{- with .Site.Params.social.linkedin -}}
{{- partial "inline/footer/connect-item.html" (dict "icon" "linkedin" "title" "LinkedIn" "url" (printf "https://linkedin.com/in/%s" .)) -}}
{{- end -}}
{{- partial "inline/connect/item.html" (dict "icon" "rss" "title" "RSS Feed" "url" ("index.xml" | relURL)) -}}
{{- partial "utils/social-connect.html" . -}}
</ul>
</div>
</div>
Expand Down Expand Up @@ -124,22 +116,3 @@ <h3 class="text-lg sm:text-xl font-semibold text-neutral-900 dark:text-neutral-5
</div>
</div>
</div>

{{- define "partials/inline/footer/connect-item.html" -}}
{{- $item := . -}}
<li>
<a
href="{{ $item.url }}"
target="_blank"
rel="noopener noreferrer"
class="group flex items-center gap-2
text-slate-600 hover:text-sky-600
dark:text-slate-300 dark:hover:text-sky-300
transition-all duration-300 ease-in-out">
<span class="transform group-hover:scale-110 transition-transform duration-300">
{{- partial "utils/icon" (dict "icon" $item.icon) -}}
</span>
<span class="transform group-hover:translate-x-1 transition-transform duration-300">{{ $item.title }}</span>
</a>
</li>
{{- end -}}
107 changes: 63 additions & 44 deletions layouts/partials/utils/share.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,68 @@
<!-- Share component -->
<div id="share">
<h2 class="text-lg font-medium text-neutral-800 dark:text-neutral-200 mb-4">
{{- i18n "shareWith" | strings.Title -}}
</h2>
<div class="flex flex-wrap justify-between gap-1 items-center space-y-1">
{{- $tag_list := "" -}}
{{- with .Params.Tags -}}
{{- $tag_list = delimit . "," -}}
{{- end -}}
{{- partial "inline/share/item.html"
(dict
"Name" "Reddit"
"Icon" "reddit"
"Title" .Title
"URL" (fmt.Print "https://reddit.com/submit?url=" .Permalink "&title=" .Title ))
-}}
{{- partial "inline/share/item.html"
(dict
"Name" "X.com"
"Icon" "twitter"
"Title" .Title
"URL" (fmt.Print "https://x.com/intent/tweet/?text=" .Title "&url= " .Permalink "&hashtags=" $tag_list))
-}}
{{- partial "inline/share/item.html"
(dict
"Name" "Facebook"
"Icon" "facebook"
"Title" .Title
"URL" (fmt.Print "https://facebook.com/sharer/sharer.php?u= " .Permalink ))
-}}
{{- partial "inline/share/item.html"
(dict
"Name" "Google"
"Icon" "google"
"Title" .Title
"URL" (fmt.Print "https://www.google.com/bookmarks/mark?op=edit&bkmk=" .Permalink "&title=" .Title ))
-}}
{{- partial "inline/share/item.html"
(dict
"Name" "Telegram"
"Icon" "telegram"
"Title" .Title
"URL" (fmt.Print "https://telegram.me/share/url?url=" .Permalink "&text=" .Title ))
-}}
</div>
{{- if not (or .Site.Params.social.share.disabled (in .Site.Params.social.share.disableByType .Type)) -}}
<h2 class="text-lg font-medium text-neutral-800 dark:text-neutral-200 mb-4">
{{- i18n "shareWith" | strings.Title -}}
</h2>
<div class="flex flex-wrap justify-between gap-1 items-center space-y-1">
{{- $tag_list := "" -}}
{{- with .Params.Tags -}}
{{- $tag_list = delimit . "," -}}
{{- end -}}

{{/* Define default social platforms */}}
{{- $default_platforms := dict
"reddit" (dict
"name" "Reddit"
"url" "https://reddit.com/submit?url=%s&title=%s")
"x" (dict
"name" "X.com"
"url" "https://x.com/intent/tweet/?text=%s&url=%s&hashtags=%s")
"facebook" (dict
"name" "Facebook"
"url" "https://facebook.com/sharer/sharer.php?u=%s")
"google" (dict
"name" "Google"
"url" "https://www.google.com/bookmarks/mark?op=edit&bkmk=%s&title=%s")
"telegram" (dict
"name" "Telegram"
"url" "https://telegram.me/share/url?url=%s&text=%s")
-}}

{{/* Render configured platforms */}}
{{- range .Site.Params.social.share.platforms -}}
{{- $platform_name := .name | lower -}}
{{- $url := .url -}}
{{- $display_name := .name | title -}}

{{/* Handle inherit platform */}}
{{- with index $default_platforms $platform_name -}}
{{- if not $url -}}
{{- $url = .url -}}
{{- end -}}
{{- $display_name = .name -}}
{{- end -}}

{{/* Generate share URL */}}
{{- $final_url := "" -}}
{{- if eq $platform_name "x" -}}
{{- $final_url = printf $url $.Title $.Permalink $tag_list -}}
{{- else if or (eq $platform_name "reddit") (eq $platform_name "google") -}}
{{- $final_url = printf $url $.Permalink $.Title -}}
{{- else if eq $platform_name "facebook" -}}
{{- $final_url = printf $url $.Permalink -}}
{{- else -}}
{{- $final_url = printf $url $.Permalink $.Title -}}
{{- end -}}

{{- partial "inline/share/item.html" (dict
"Name" $display_name
"Title" $.Title
"URL" $final_url)
-}}
{{- end -}}
</div>
{{- end -}}
</div>

{{- define "partials/inline/share/item.html" -}}
Expand Down
43 changes: 43 additions & 0 deletions layouts/partials/utils/social-connect.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- with .Site.Params.social -}}
{{- $social := . -}}
{{- with .connect -}}

{{- $platformMap := dict
"github" (dict "icon" "github" "title" "Github" "config" $social.github "urlFormat" "https://github.com/%s")
"x" (dict "icon" "xcom" "title" "X.com" "config" $social.twitter "urlFormat" "https://x.com/%s")
"linkedin" (dict "icon" "linkedin" "title" "LinkedIn" "config" $social.linkedin "urlFormat" "https://linkedin.com/in/%s")
}}

{{- range .platforms -}}
{{- $platformName := . -}}
{{- $platform := index $platformMap $platformName -}}
{{- with $platform -}}
{{- if .config -}}
{{- $url := printf .urlFormat $platformName -}}
{{- partial "inline/connect/item.html" (dict "icon" .icon "title" .title "url" $url) -}}
{{- end -}}
{{- end -}}

{{- end -}}
{{- end -}}

{{- end -}}

{{- define "partials/inline/connect/item.html" -}}
{{- $item := . -}}
<li>
<a
href="{{ $item.url }}"
target="_blank"
rel="noopener noreferrer"
class="group flex items-center gap-2
text-slate-600 hover:text-sky-600
dark:text-slate-300 dark:hover:text-sky-300
transition-all duration-300 ease-in-out">
<span class="transform group-hover:scale-110 transition-transform duration-300">
{{- partial "utils/icon" (dict "icon" $item.icon) -}}
</span>
<span class="transform group-hover:translate-x-1 transition-transform duration-300">{{ $item.title }}</span>
</a>
</li>
{{- end -}}
1 change: 1 addition & 0 deletions theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ license = 'MIT'
licenselink = 'https://github.com/wayjam/hugo-theme-fluidity/blob/master/LICENSE'
description = 'A fluid and responsive Hugo theme.'
homepage = 'https://github.com/wayjam/hugo-theme-fluidity'
demositev = "https://wayjam.github.io/hugo-theme-fluidity"
tags = ["blog", "fluent", "clean", "simple", "light", "dark" ,"writing", "syntax highlighting", "archives", "tailwindcss", "search", "emoji", "math typesetting", "fluent-design"]
features = ["blog", "responsive", "social media", "archives"]
[author]
Expand Down