Skip to content

Commit

Permalink
trying comment implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
BedirT committed Mar 3, 2024
1 parent d45d0d9 commit 8bbbe36
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 3 deletions.
3 changes: 1 addition & 2 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ params:
disableSpecial1stPost: false
disableScrollToTop: false
hideAuthor: true
comments: true
hidemeta: false
hideSummary: false
showtoc: false
Expand All @@ -80,7 +79,7 @@ params:
commentSystems:
remark42:
url: https://comments.bedirtapkan.com
site: https://bedirtapkan.com
site: bedirtapkan_com
defaultCommentSystems:
remark42: true

Expand Down
65 changes: 65 additions & 0 deletions layouts/_default/single.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{{- define "main" }}

<article class="post-single">
<header class="post-header">
{{ partial "breadcrumbs.html" . }}
<h1 class="post-title entry-hint-parent">
{{ .Title }}
{{- if .Draft }}
<span class="entry-hint" title="Draft">
<svg xmlns="http://www.w3.org/2000/svg" height="35" viewBox="0 -960 960 960" fill="currentColor">
<path
d="M160-410v-60h300v60H160Zm0-165v-60h470v60H160Zm0-165v-60h470v60H160Zm360 580v-123l221-220q9-9 20-13t22-4q12 0 23 4.5t20 13.5l37 37q9 9 13 20t4 22q0 11-4.5 22.5T862.09-380L643-160H520Zm300-263-37-37 37 37ZM580-220h38l121-122-18-19-19-18-122 121v38Zm141-141-19-18 37 37-18-19Z" />
</svg>
</span>
{{- end }}
</h1>
{{- if .Description }}
<div class="post-description">
{{ .Description }}
</div>
{{- end }}
{{- if not (.Param "hideMeta") }}
<div class="post-meta">
{{- partial "post_meta.html" . -}}
{{- partial "translation_list.html" . -}}
{{- partial "edit_post.html" . -}}
{{- partial "post_canonical.html" . -}}
</div>
{{- end }}
</header>
{{- $isHidden := (.Param "cover.hiddenInSingle") | default (.Param "cover.hidden") | default false }}
{{- partial "cover.html" (dict "cxt" . "IsSingle" true "isHidden" $isHidden) }}
{{- if (.Param "ShowToc") }}
{{- partial "toc.html" . }}
{{- end }}

{{- if .Content }}
<div class="post-content">
{{- if not (.Param "disableAnchoredHeadings") }}
{{- partial "anchored_headings.html" .Content -}}
{{- else }}{{ .Content }}{{ end }}
</div>
{{- end }}

<footer class="post-footer">
{{- $tags := .Language.Params.Taxonomies.tag | default "tags" }}
<ul class="post-tags">
{{- range ($.GetTerms $tags) }}
<li><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
{{- end }}
</ul>
{{- if (.Param "ShowPostNavLinks") }}
{{- partial "post_nav_links.html" . }}
{{- end }}
{{- if (and site.Params.ShowShareButtons (ne .Params.disableShare true)) }}
{{- partial "share_icons.html" . -}}
{{- end }}
</footer>

{{- if not (.Param "noComments") }}
{{- partial "comments.html" . }}
{{- end }}
</article>

{{- end }}{{/* end main */}}
15 changes: 15 additions & 0 deletions layouts/partials/comments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- /* You can add your own layouts/comments.html to override this file */ -}}

{{- $pageCommentSystems := .Param "pageCommentSystems"}}
{{- if not $pageCommentSystems }}
{{- $pageCommentSystems = site.Params.defaultCommentSystems }}
{{- end }}

{{- $page := . -}}
{{- with site.Params.commentSystems -}}
{{- if $pageCommentSystems.remark42 -}}
{{- with .remark42 -}}
{{- partial "remark42.html" (dict "page" $page "ctx" .) }}
{{- end -}}
{{- end -}}
{{- end -}}
58 changes: 58 additions & 0 deletions layouts/partials/remark42.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<div class="comments">
<div class="title">
<span>Comments</span>
<span class="counter"><span class="remark42__counter" data-url="{{ .page.Permalink }}"></span></span>
</div>
<div id="remark42">
</div>
</div>

<script>
var remark_config = {
host: '{{ .ctx.url }}',
site_id: '{{ .ctx.site }}',
components: ['embed', 'counter'],
max_shown_comments: 20,
theme: 'light',
simple_view: true,
admonition: JSON.stringify(['Please subscribe by email to receive reply notifications.']),
};
if (isDarkTheme()) {
remark_config.theme = 'dark'
}

(function() {
// toogle theme callback
const key = 'remark42'
if (!toggleThemeCallbacks.hasOwnProperty(key)) {
toggleThemeCallbacks[key] = (isDark) => {
const remark42 = window.REMARK42
if (!remark42 || !document.querySelector('#remark42')) {
return;
}
if (isDark) {
remark42.changeTheme('light');
} else {
remark42.changeTheme('dark');
}
}
}

// init or reset remark42
const remark42 = window.REMARK42
if (remark42) {
remark42.destroy()
remark42.createInstance(remark_config)
} else {
for (const component of remark_config.components) {
var d = document, s = d.createElement('script');
s.src = `${remark_config.host}/web/${component}.mjs`;
s.type = 'module';
s.defer = true;
// prevent the <script> from loading mutiple times by InstantClick
s.setAttribute('data-no-instant', '')
d.head.appendChild(s);
}
}
})();
</script>
2 changes: 1 addition & 1 deletion themes/PaperMod

0 comments on commit 8bbbe36

Please sign in to comment.