mirror of
https://github.com/nunocoracao/blowfish.git
synced 2025-01-22 22:45:42 -06:00
154 lines
5.6 KiB
HTML
154 lines
5.6 KiB
HTML
{{ define "main" }}
|
|
<article>
|
|
<header class="max-w-prose">
|
|
{{ if .Params.showBreadcrumbs | default (.Site.Params.article.showBreadcrumbs | default false) }}
|
|
{{ partial "breadcrumbs.html" . }}
|
|
{{ end }}
|
|
<h1 class="mt-0 text-4xl font-extrabold text-neutral-900 dark:text-neutral">
|
|
{{ .Title | emojify }}
|
|
</h1>
|
|
<div class="mt-8 mb-12 text-base text-neutral-500 dark:text-neutral-400 print:hidden">
|
|
{{ partial "article-meta.html" (dict "context" . "scope" "single") }}
|
|
</div>
|
|
</header>
|
|
<section class="flex flex-col max-w-full mt-0 prose dark:prose-invert lg:flex-row">
|
|
{{ if and (.Params.showTableOfContents | default (.Site.Params.article.showTableOfContents | default false)) (in
|
|
.TableOfContents "<ul") }} <div class="order-first px-0 lg:order-last lg:max-w-xs ltr:lg:pl-8 rtl:lg:pr-8">
|
|
<div class="toc ltr:pl-5 rtl:pr-5 print:hidden lg:sticky lg:top-10">
|
|
{{ partial "toc.html" . }}
|
|
</div>
|
|
</div>
|
|
{{ end }}
|
|
<div class="min-w-0 min-h-0 max-w-prose">
|
|
{{ .Content | emojify }}
|
|
</div>
|
|
<script>
|
|
|
|
var liked_article = false
|
|
|
|
if (typeof auth !== 'undefined') {
|
|
var oid = "views_{{ .File.Path }}"
|
|
var id = oid ? oid.replaceAll("/", "-") : oid
|
|
|
|
var viewed = localStorage.getItem(id);
|
|
|
|
if (!viewed) {
|
|
auth.signInAnonymously()
|
|
.then(() => {
|
|
var docRef = db.collection('views').doc(id)
|
|
localStorage.setItem(id, true);
|
|
docRef.get().then((doc) => {
|
|
if (doc.exists) {
|
|
db.collection('views').doc(id).update({
|
|
views: firebase.firestore.FieldValue.increment(1)
|
|
});
|
|
} else {
|
|
db.collection('views').doc(id).set({ views: 1 })
|
|
}
|
|
}).catch((error) => {
|
|
console.log("Error getting document:", error);
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
var errorCode = error.code;
|
|
var errorMessage = error.message;
|
|
console.error(errorCode, errorMessage)
|
|
});
|
|
}
|
|
|
|
var oid_likes = "likes_{{ .File.Path }}"
|
|
var id_likes = oid_likes ? oid_likes.replaceAll("/", "-") : oid_likes
|
|
|
|
var liked = localStorage.getItem(id_likes);
|
|
|
|
if (liked) {
|
|
liked_article = true
|
|
document.querySelectorAll("button[id='likes_button']")[0].innerText = "Remove Like"
|
|
}
|
|
|
|
}
|
|
|
|
function like_article(id_likes) {
|
|
console.log("add")
|
|
liked_article = true
|
|
localStorage.setItem(id_likes, true);
|
|
document.querySelectorAll("button[id='likes_button']")[0].innerText = "Remove Like"
|
|
auth.signInAnonymously()
|
|
.then(() => {
|
|
var docRef = db.collection('likes').doc(id_likes)
|
|
docRef.get().then((doc) => {
|
|
if (doc.exists) {
|
|
db.collection('likes').doc(id_likes).update({
|
|
likes: firebase.firestore.FieldValue.increment(1)
|
|
});
|
|
} else {
|
|
db.collection('likes').doc(id_likes).set({ likes: 1 })
|
|
}
|
|
}).catch((error) => {
|
|
console.log("Error getting document:", error);
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
var errorCode = error.code;
|
|
var errorMessage = error.message;
|
|
console.error(errorCode, errorMessage)
|
|
});
|
|
}
|
|
|
|
function remove_like_article(id_likes) {
|
|
console.log("remove")
|
|
liked_article = false
|
|
localStorage.setItem(id_likes, false);
|
|
document.querySelectorAll("button[id='likes_button']")[0].innerText = "Like"
|
|
auth.signInAnonymously()
|
|
.then(() => {
|
|
var docRef = db.collection('likes').doc(id_likes)
|
|
docRef.get().then((doc) => {
|
|
if (doc.exists) {
|
|
db.collection('likes').doc(id_likes).update({
|
|
likes: firebase.firestore.FieldValue.increment(-1)
|
|
});
|
|
} else {
|
|
db.collection('likes').doc(id_likes).set({ likes: 0 })
|
|
}
|
|
}).catch((error) => {
|
|
console.log("Error getting document:", error);
|
|
});
|
|
})
|
|
.catch((error) => {
|
|
var errorCode = error.code;
|
|
var errorMessage = error.message;
|
|
console.error(errorCode, errorMessage)
|
|
});
|
|
}
|
|
|
|
function process_article() {
|
|
var oid_likes = "likes_{{ .File.Path }}"
|
|
var id_likes = oid_likes ? oid_likes.replaceAll("/", "-") : oid_likes
|
|
if (!liked_article) {
|
|
like_article(id_likes)
|
|
} else {
|
|
remove_like_article(id_likes)
|
|
}
|
|
}
|
|
</script>
|
|
</section>
|
|
<footer class="pt-8 max-w-prose print:hidden">
|
|
{{ partial "author.html" . }}
|
|
{{ partial "sharing-links.html" . }}
|
|
{{ partial "article-pagination.html" . }}
|
|
{{ if .Params.showComments | default (.Site.Params.article.showComments | default false) }}
|
|
{{ if templates.Exists "partials/comments.html" }}
|
|
<div class="pt-3">
|
|
<hr class="border-dotted border-neutral-300 dark:border-neutral-600" />
|
|
<div class="pt-3">
|
|
{{ partial "comments.html" . }}
|
|
</div>
|
|
</div>
|
|
{{ else }}
|
|
{{ warnf "[BLOWFISH] Comments are enabled for %s but no comments partial exists." .File.Path }}
|
|
{{ end }}
|
|
{{ end }}
|
|
</footer>
|
|
</article>
|
|
{{ end }}
|