Skip to content

Commit

Permalink
feat(comments): add Giscus integration for comments in the book
Browse files Browse the repository at this point in the history
  • Loading branch information
entelecheia committed Jul 13, 2024
1 parent 377a3c7 commit 3b45187
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
16 changes: 16 additions & 0 deletions book/_addons/giscus.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script src="https://giscus.app/client.js"
data-repo="entelecheia/nlp4ss"
data-repo-id="R_kgDOMTcakg"
data-category="Q&A"
data-category-id="DIC_kwDOMTcaks4Cgwzd"
data-mapping="pathname"
data-strict="1"
data-reactions-enabled="1"
data-emit-metadata="1"
data-input-position="bottom"
data-theme="preferred_color_scheme"
data-lang="__CURRENT_LANGUAGE__"
data-loading="lazy"
crossorigin="anonymous"
async>
</script>
15 changes: 14 additions & 1 deletion book/_scripts/postprocessing.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ FINAL_BUILD_DIR="book/_build/html"
LANGUAGE_SELECTOR_FILE="book/_addons/language_selector.html"
REDIRECT_INDEX_FILE="book/_addons/language_redirect.html"
FINAL_INDEX_FILE="$FINAL_BUILD_DIR/index.html"
GISCUS_SCRIPT_FILE="book/_addons/giscus.html"

# Function to copy and modify HTML files
copy_and_modify_html() {
Expand Down Expand Up @@ -44,10 +45,16 @@ copy_and_modify_html() {
# Replace language options
selector_content="${selector_content/__LANGUAGE_OPTIONS__/$options}"

# Define the Giscus script
local giscus_script
giscus_script=$(cat "$GISCUS_SCRIPT_FILE")
giscus_script="${giscus_script//$'\n'/}"
giscus_script="${giscus_script/__CURRENT_LANGUAGE__/$lang}"

# Modify HTML files
find "$dest_dir" -name "*.html" -print0 | while IFS= read -r -d '' html_file; do
# Add language selector and script
awk -v selector="$selector_content" '
awk -v selector="$selector_content" -v giscus="$giscus_script" '
/<\/head>/ {
print " <script src=\"/_static/language_switcher.js\"></script>"
print $0
Expand All @@ -58,6 +65,12 @@ copy_and_modify_html() {
print selector
next
}
/<footer class="prev-next-footer d-print-none">/ {
print " <div class=\"giscus\"></div>"
print giscus
print $0
next
}
{print}
' "$html_file" >"${html_file}.tmp" && mv "${html_file}.tmp" "$html_file"
done
Expand Down

0 comments on commit 3b45187

Please sign in to comment.