-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Generate homepage topics on server side (#2766)
- Loading branch information
1 parent
ca0b544
commit 455f18b
Showing
7 changed files
with
436 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright (c) 2024 Jonah Aragon <[email protected]> | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
|
||
name: 🔄 Update Discussions | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "*/30 * * * *" | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
generate: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
environment: | ||
name: production | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: "false" | ||
fetch-depth: 1 | ||
|
||
- name: Create site/en directory | ||
run: mkdir -p site/en | ||
|
||
- name: Update Discussions | ||
uses: yakubique/[email protected] | ||
with: | ||
endpoint: https://${{ vars.PROD_GARAGE_HOSTNAME }} | ||
access_key: ${{ secrets.PROD_GARAGE_KEY_ID }} | ||
secret_key: ${{ secrets.PROD_GARAGE_SECRET_KEY }} | ||
bucket: ${{ vars.PROD_GARAGE_BUCKET }} | ||
source: /en/index.html | ||
target: ./site/en/ | ||
|
||
- name: Run index-generation.sh for top posts | ||
run: | | ||
bash index-generation.sh \ | ||
--source='https://discuss.privacyguides.net/top.json?period=weekly' \ | ||
--tag="top posts" \ | ||
--destination="./site/en/index.html" \ | ||
--count=3 | ||
- name: Run index-generation.sh for latest posts | ||
run: | | ||
bash index-generation.sh \ | ||
--source='https://discuss.privacyguides.net/latest.json' \ | ||
--tag="latest posts" \ | ||
--destination="./site/en/index.html" \ | ||
--count=12 | ||
- name: Upload modified index | ||
uses: yakubique/[email protected] | ||
with: | ||
endpoint: https://${{ vars.PROD_GARAGE_HOSTNAME }} | ||
access_key: ${{ secrets.PROD_GARAGE_KEY_ID }} | ||
secret_key: ${{ secrets.PROD_GARAGE_SECRET_KEY }} | ||
bucket: ${{ vars.PROD_GARAGE_BUCKET }} | ||
source: ./site/en/index.html | ||
target: /en |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/bin/bash | ||
|
||
DATE_CMD="date" | ||
|
||
# Check if the script is running on macOS | ||
if [[ "$OSTYPE" == "darwin"* ]]; then | ||
DATE_CMD="gdate" | ||
fi | ||
|
||
# Defaults | ||
source="https://discuss.privacyguides.net/top.json?period=weekly" | ||
tag="top posts" | ||
destination="./site/en/index.html" | ||
count=3 | ||
|
||
for arg in "$@" | ||
do | ||
case $arg in | ||
--source=*) | ||
source="${arg#*=}" | ||
shift | ||
;; | ||
--tag=*) | ||
tag="${arg#*=}" | ||
shift | ||
;; | ||
--destination=*) | ||
destination="${arg#*=}" | ||
shift | ||
;; | ||
--count=*) | ||
count="${arg#*=}" | ||
shift | ||
;; | ||
esac | ||
done | ||
|
||
# URL of the Discourse top.json | ||
DISCOURSE_URL="$source" | ||
|
||
# Fetch the JSON data | ||
json_data=$(curl -s $DISCOURSE_URL) | ||
|
||
# Extract the first 3 topics | ||
topics=$(echo $json_data | jq -r ".topic_list.topics[:$count]") | ||
|
||
users=$(echo $json_data | jq -r ".users") | ||
# Generate HTML for the first 3 posts | ||
html_output="" | ||
for row in $(echo "${topics}" | jq -r '.[] | @base64'); do | ||
_jq() { | ||
echo ${row} | base64 --decode | jq -r ${1} | ||
} | ||
|
||
title=$(_jq '.title') | ||
id=$(_jq '.id') | ||
like_count=$(_jq '.like_count') | ||
reply_count=$(_jq '.posts_count') | ||
views=$(_jq '.views') | ||
|
||
author_id=$(_jq '.posters[0].user_id') | ||
author_info=$(echo "${users}" | jq -r ".[] | select(.id==$author_id)") | ||
author_username=$(echo "${author_info}" | jq -r ".username") | ||
|
||
html_output+="<li class='discourse-topic'>" | ||
html_output+="<p class='discourse-title'><a href='https://discuss.privacyguides.net/t/${id}'><strong>${title}</strong></a></p>" | ||
html_output+="<hr>" | ||
html_output+="<p class='discourse-author'>" | ||
html_output+="<span class='discourse-author'>" | ||
html_output+="<img src='https://forum-cdn.privacyguides.net/user_avatar/discuss.privacyguides.net/${author_username}/48/1.png' loading='lazy' aria-hidden='true' alt='${author_username}' width='20' height='20' class='middle'>" | ||
html_output+="<span> Posted by <em>$author_username</em></span>" | ||
html_output+="</span>" | ||
html_output+="</p>" | ||
html_output+="<p class='discourse-data'>" | ||
html_output+="<span class='twemoji'><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><title>eye</title><path d='M12,9A3,3 0 0,0 9,12A3,3 0 0,0 12,15A3,3 0 0,0 15,12A3,3 0 0,0 12,9M12,17A5,5 0 0,1 7,12A5,5 0 0,1 12,7A5,5 0 0,1 17,12A5,5 0 0,1 12,17M12,4.5C7,4.5 2.73,7.61 1,12C2.73,16.39 7,19.5 12,19.5C17,19.5 21.27,16.39 23,12C21.27,7.61 17,4.5 12,4.5Z' /></svg></span>" | ||
html_output+="<span class='discourse-views'> ${views} </span>" | ||
html_output+="<span class='twemoji pg-red'><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><title>heart</title><path d='M12,21.35L10.55,20.03C5.4,15.36 2,12.27 2,8.5C2,5.41 4.42,3 7.5,3C9.24,3 10.91,3.81 12,5.08C13.09,3.81 14.76,3 16.5,3C19.58,3 22,5.41 22,8.5C22,12.27 18.6,15.36 13.45,20.03L12,21.35Z' /></svg></span>" | ||
html_output+="<span class='discourse-likes'> ${like_count} </span>" | ||
html_output+="<span class='twemoji'><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><title>reply</title><path d='M10,9V5L3,12L10,19V14.9C15,14.9 18.5,16.5 21,20C20,15 17,10 10,9Z' /></svg></span>" | ||
html_output+="<span class='discourse-replies'> ${reply_count} </span>" | ||
html_output+="</p>" | ||
html_output+="</li>" | ||
done | ||
|
||
tempfile=$(mktemp) | ||
echo "$html_output" > $tempfile | ||
|
||
# Insert the HTML output between the comments in index.html | ||
sed -i'.bak' "/<!-- start $tag -->/,/<!-- end $tag -->/{//!d;}; /<!-- start $tag -->/r $tempfile" $destination |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
# Copyright (c) 2022-2024 Jonah Aragon <[email protected]> | ||
|
||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to | ||
# deal in the Software without restriction, including without limitation the | ||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
# sell copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
|
||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
|
||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
# IN THE SOFTWARE. | ||
|
||
docs_dir: "net" | ||
site_url: "https://www.privacyguides.net/" | ||
site_dir: "site/net" | ||
|
||
site_name: Privacy Guides Community | ||
site_description: "Discover privacy tools and resources, ask questions, and stay informed at the biggest digital rights and privacy tech community online." | ||
edit_uri_template: blob/main/net/{path}?plain=1 | ||
|
||
extra: | ||
privacy_guides: | ||
footer: | ||
intro: | ||
!ENV [ | ||
FOOTER_INTRO, | ||
"Privacy Guides is a non-profit, socially motivated website that provides information for protecting your data security and privacy.", | ||
] | ||
note: | ||
!ENV [ | ||
FOOTER_NOTE, | ||
"We do not make money from recommending certain products, and we do not use affiliate links.", | ||
] | ||
copyright: | ||
author: | ||
!ENV [FOOTER_COPYRIGHT_AUTHOR, "Privacy Guides and contributors."] | ||
date: !ENV [FOOTER_COPYRIGHT_DATE, "2019-2024"] | ||
license: | ||
- fontawesome/brands/creative-commons | ||
- fontawesome/brands/creative-commons-by | ||
- fontawesome/brands/creative-commons-sa | ||
homepage: https://www.privacyguides.org/en/ | ||
generator: false | ||
context: !ENV [BUILD_CONTEXT, "production"] | ||
offline: !ENV [BUILD_OFFLINE, false] | ||
deploy: !ENV DEPLOY_ID | ||
social: | ||
- icon: simple/mastodon | ||
link: https://mastodon.neat.computer/@privacyguides | ||
name: !ENV [SOCIAL_MASTODON, "Mastodon"] | ||
- icon: simple/matrix | ||
link: https://matrix.to/#/#privacyguides:matrix.org | ||
name: !ENV [SOCIAL_MATRIX, "Matrix"] | ||
- icon: simple/discourse | ||
link: https://discuss.privacyguides.net/ | ||
name: !ENV [SOCIAL_FORUM, "Forum"] | ||
- icon: simple/github | ||
link: https://github.com/privacyguides | ||
name: !ENV [SOCIAL_GITHUB, "GitHub"] | ||
- icon: simple/torbrowser | ||
link: http://www.xoe4vn5uwdztif6goazfbmogh6wh5jc4up35bqdflu6bkdc5cas5vjqd.onion/ | ||
name: !ENV [SOCIAL_TOR_SITE, "Hidden service"] | ||
|
||
repo_url: | ||
!ENV [BUILD_REPO_URL, "https://github.com/privacyguides/privacyguides.org"] | ||
repo_name: "" | ||
|
||
theme: | ||
name: material | ||
language: en | ||
custom_dir: theme | ||
font: | ||
text: Public Sans | ||
code: DM Mono | ||
palette: | ||
- media: "(prefers-color-scheme)" | ||
scheme: default | ||
accent: deep purple | ||
toggle: | ||
icon: material/brightness-auto | ||
name: !ENV [THEME_DARK, "Switch to dark mode"] | ||
- media: "(prefers-color-scheme: dark)" | ||
scheme: slate | ||
accent: amber | ||
toggle: | ||
icon: material/brightness-2 | ||
name: !ENV [THEME_LIGHT, "Switch to light mode"] | ||
- media: "(prefers-color-scheme: light)" | ||
scheme: default | ||
accent: deep purple | ||
toggle: | ||
icon: material/brightness-5 | ||
name: !ENV [THEME_AUTO, "Switch to system theme"] | ||
favicon: assets/brand/logos/png/favicon-32x32.png | ||
icon: | ||
repo: simple/github | ||
features: | ||
- announce.dismiss | ||
- navigation.tracking | ||
- navigation.tabs | ||
- navigation.sections | ||
- navigation.expand | ||
- navigation.path | ||
- navigation.indexes | ||
- navigation.footer | ||
- content.action.edit | ||
- content.tabs.link | ||
- content.tooltips | ||
- search.highlight | ||
|
||
extra_css: | ||
- assets/stylesheets/extra.css?v=20240829 | ||
|
||
watch: | ||
- theme | ||
- includes | ||
|
||
plugins: | ||
tags: {} | ||
privacy: | ||
enabled: !ENV [BUILD_PRIVACY, true] | ||
offline: | ||
enabled: !ENV [BUILD_OFFLINE, false] | ||
group: | ||
enabled: !ENV [BUILD_INSIDERS, true] | ||
plugins: | ||
macros: {} | ||
meta: {} | ||
optimize: | ||
enabled: !ENV [OPTIMIZE, PRODUCTION, NETLIFY, false] | ||
typeset: {} | ||
social: | ||
cards: !ENV [CARDS, true] | ||
cards_dir: assets/img/social | ||
cards_layout_dir: theme/layouts | ||
cards_layout: page | ||
|
||
markdown_extensions: | ||
admonition: {} | ||
pymdownx.details: {} | ||
pymdownx.superfences: | ||
custom_fences: | ||
- name: mermaid | ||
class: mermaid | ||
format: !!python/name:pymdownx.superfences.fence_code_format | ||
pymdownx.tabbed: | ||
alternate_style: true | ||
pymdownx.arithmatex: | ||
generic: true | ||
pymdownx.critic: {} | ||
pymdownx.caret: {} | ||
pymdownx.keys: {} | ||
pymdownx.mark: {} | ||
pymdownx.tilde: {} | ||
pymdownx.snippets: | ||
auto_append: | ||
- !ENV [BUILD_ABBREVIATIONS, "includes/abbreviations.en.txt"] | ||
pymdownx.tasklist: | ||
custom_checkbox: true | ||
attr_list: {} | ||
def_list: {} | ||
md_in_html: {} | ||
meta: {} | ||
abbr: {} | ||
pymdownx.emoji: | ||
emoji_index: !!python/name:material.extensions.emoji.twemoji | ||
emoji_generator: !!python/name:material.extensions.emoji.to_svg | ||
tables: {} | ||
footnotes: {} | ||
toc: | ||
permalink: true | ||
toc_depth: 4 | ||
|
||
nav: | ||
- !ENV [NAV_HOME, "Home"]: https://www.privacyguides.org/en/ | ||
- !ENV [NAV_KNOWLEDGE_BASE, "Knowledge Base"]: | ||
https://www.privacyguides.org/en/basics/why-privacy-matters/ | ||
- !ENV [NAV_RECOMMENDATIONS, "Recommendations"]: | ||
https://www.privacyguides.org/en/tools/ | ||
- !ENV [NAV_BLOG, "Articles"]: https://www.privacyguides.org/articles/ | ||
- !ENV [NAV_ABOUT, "About"]: https://www.privacyguides.org/en/about/ | ||
- "Donate": https://www.privacyguides.org/en/about/donate/ | ||
- !ENV [NAV_CHANGELOG, "Changelog"]: | ||
"https://github.com/privacyguides/privacyguides.org/releases" | ||
- !ENV [NAV_FORUM, "Forum"]: "https://discuss.privacyguides.net/" | ||
|
||
validation: | ||
nav: | ||
not_found: info |
Oops, something went wrong.