From b50490ab4412271da32b254bb086e3597677920d Mon Sep 17 00:00:00 2001 From: Nathan Price Date: Fri, 17 Jan 2025 15:46:39 -0500 Subject: [PATCH] migrated to my fork of quartz that uses a json config --- .dockerignore | 7 ++ .gitignore | 3 +- Dockerfile | 45 ++++--------- config.json | 144 ++++++++++++++++++++++++++++++++++++++++++ default.conf.template | 2 +- docker-compose.yml | 36 ++--------- entrypoint.sh | 90 ++++++++++---------------- 7 files changed, 204 insertions(+), 123 deletions(-) create mode 100644 config.json diff --git a/.dockerignore b/.dockerignore index e69de29..43e0212 100644 --- a/.dockerignore +++ b/.dockerignore @@ -0,0 +1,7 @@ +.vscode/ +config/ +content/ +LICENSE +Makefile +README.md +.env diff --git a/.gitignore b/.gitignore index 8b13789..a283517 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ - +config/ +.env diff --git a/Dockerfile b/Dockerfile index 80f4c50..86b0a84 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,18 @@ FROM node:alpine AS build RUN apk --no-cache add git && \ - git clone https://github.com/jackyzha0/quartz.git && \ - cd quartz && git checkout v4.4.0 && cd .. && \ + git clone https://code.modernleft.org/gravityfargo/quartz.git && \ + cd quartz && git switch json-config && cd .. && \ mkdir -p /usr/share/nginx/html && \ mv quartz/* /usr/share/nginx/html && \ - rm -rf /usr/share/nginx/html/docs && \ cd /usr/share/nginx/html && \ npm ci && npx quartz build && \ - rm -rf /usr/share/nginx/html/node_modules + rm -rf /usr/share/nginx/html/node_modules /usr/share/nginx/html/docs FROM nginx:stable-alpine3.20 COPY --from=build /usr/share/nginx/html /usr/share/nginx/html COPY default.conf.template /etc/nginx/templates/default.conf.template +COPY config.json /usr/share/nginx/html/default-config.json WORKDIR /usr/share/nginx/html @@ -20,47 +20,24 @@ RUN apk --no-cache add nodejs npm bash dumb-init git && \ rm -rf /var/cache/apk/* && \ echo "*/5 * * * * cd /usr/share/nginx/html/content && git pull >/dev/null 2>&1 && cd /usr/share/nginx/html && npx quartz build >/dev/null 2>&1" > /etc/crontabs/root -RUN ln -s /usr/share/nginx/html/content / && \ +RUN mkdir /config && \ + ln -s /usr/share/nginx/html/content / && \ chown -R nginx:nginx /usr/share/nginx/html && \ - chown -R nginx:nginx /usr/share/nginx/html/content + chown -R nginx:nginx /config +# REQUIRED +ENV NGINX_PORT=80 ENV ENABLE_CRON="false" ENV BUILD_SCHEDULE="*/5 * * * *" -ENV NGINX_PORT=80 -ENV BASE_URL="quartz.zhao.xyz" -ENV PAGE_TITLE="Quartz Docker" -ENV ENABLE_SPA="true" -ENV ENABLE_POPOVERS="true" -ENV ANALYTICS_PROVIDER="plausible" -ENV IGNORE_PATTERNS="private,templates" -ENV TYPOGRAPHY_HEADER="Schibsted Grotesk" -ENV TYPOGRAPHY_BODY="Source Sans Pro" -ENV TYPOGRAPHY_CODE="IBM-Plex Mono" -ENV LIGHTMODE_LIGHT="#faf8f8" -ENV LIGHTMODE_LIGHTGRAY="#e5e5e5" -ENV LIGHTMODE_GRAY="#bbbbbb" -ENV LIGHTMODE_DARKGRAY="#4e4e4e" -ENV LIGHTMODE_DARK="#2b2b2b" -ENV LIGHTMODE_SECONDARY="#284b63" -ENV LIGHTMODE_TERTIARY="#84a59d" -ENV LIGHTMODE_HIGHLIGHT="rgba(143,159,169,0.15)" -ENV DARKMODE_LIGHT="#161618" -ENV DARKMODE_LIGHTGRAY="#393639" -ENV DARKMODE_GRAY="#646464" -ENV DARKMODE_DARKGRAY="#4d4d4d" -ENV DARKMODE_DARK="#ebebec" -ENV DARKMODE_SECONDARY="#7b97aa" -ENV DARKMODE_TERTIARY="#84a59d" -ENV DARKMODE_HIGHLIGHT="rgba(143,159,169,0.15)" +ENV SERVER_NAME="quartz.zhao.xyz" +ENV QUARTZ_CONFIG_PATH="/config/config.json" COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh ENTRYPOINT ["dumb-init", "--"] - CMD ["/entrypoint.sh"] - LABEL org.opencontainers.image.source="https://code.modernleft.org/gravityfargo/quartz-docker" LABEL org.opencontainers.image.url="https://quartz.jzhao.xyz/" LABEL org.opencontainers.image.description="A docker image for Quartz, a static site generator." diff --git a/config.json b/config.json new file mode 100644 index 0000000..5cc2407 --- /dev/null +++ b/config.json @@ -0,0 +1,144 @@ +{ + "configuration": { + "pageTitle": "quartz-docker ;)", + "pageTitleSuffix": "", + "enableSPA": true, + "enablePopovers": true, + "analytics": { + "provider": "plausible" + }, + "locale": "en-US", + "baseUrl": "quartz.jzhao.xyz", + "ignorePatterns": [ + "private", + "templates", + ".obsidian" + ], + "defaultDateType": "created", + "generateSocialImages": false, + "theme": { + "fontOrigin": "googleFonts", + "cdnCaching": true, + "typography": { + "header": "Schibsted Grotesk", + "body": "Source Sans Pro", + "code": "IBM Plex Mono" + }, + "colors": { + "lightMode": { + "light": "#faf8f8", + "lightgray": "#e5e5e5", + "gray": "#b8b8b8", + "darkgray": "#4e4e4e", + "dark": "#2b2b2b", + "secondary": "#284b63", + "tertiary": "#84a59d", + "highlight": "rgba(143, 159, 169, 0.15)", + "textHighlight": "#fff23688" + }, + "darkMode": { + "light": "#161618", + "lightgray": "#393639", + "gray": "#646464", + "darkgray": "#d4d4d4", + "dark": "#ebebec", + "secondary": "#7b97aa", + "tertiary": "#84a59d", + "highlight": "rgba(143, 159, 169, 0.15)", + "textHighlight": "#b3aa0288" + } + } + } + }, + "plugins": { + "transformers": [ + { + "name": "FrontMatter" + }, + { + "name": "CreatedModifiedDate", + "config": { + "priority": [ + "frontmatter", + "filesystem" + ] + } + }, + { + "name": "SyntaxHighlighting", + "config": { + "theme": { + "light": "github-light", + "dark": "github-dark" + }, + "keepBackground": false + } + }, + { + "name": "ObsidianFlavoredMarkdown", + "config": { + "enableInHtmlEmbed": false + } + }, + { + "name": "GitHubFlavoredMarkdown" + }, + { + "name": "TableOfContents" + }, + { + "name": "CrawlLinks", + "config": { + "markdownLinkResolution": "shortest" + } + }, + { + "name": "Description" + }, + { + "name": "Latex", + "config": { + "renderEngine": "katex" + } + } + ], + "filters": [ + { + "name": "RemoveDrafts" + } + ], + "emitters": [ + { + "name": "AliasRedirects" + }, + { + "name": "ComponentResources" + }, + { + "name": "ContentPage" + }, + { + "name": "FolderPage" + }, + { + "name": "TagPage" + }, + { + "name": "ContentIndex", + "config": { + "enableSiteMap": true, + "enableRSS": true + } + }, + { + "name": "Assets" + }, + { + "name": "Static" + }, + { + "name": "NotFoundPage" + } + ] + } +} \ No newline at end of file diff --git a/default.conf.template b/default.conf.template index b94f123..3293961 100644 --- a/default.conf.template +++ b/default.conf.template @@ -1,6 +1,6 @@ server { listen ${NGINX_PORT}; - server_name ${BASE_URL}; + server_name ${SERVER_NAME}; root /usr/share/nginx/html/public; index index.html; error_page 404 /404.html; diff --git a/docker-compose.yml b/docker-compose.yml index 76d4b41..ab48470 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,41 +4,17 @@ services: image: code.modernleft.org/gravityfargo/quartz-docker:dev ports: - 80:8080 + env_file: + - .env environment: NGINX_PORT: 8080 - ENABLE_CRON: "false" + SERVER_NAME: "localhost" + ENABLE_CRON: "true" BUILD_SCHEDULE: "*/10 * * * *" - PAGE_TITLE: "Quartz Docker" - ENABLE_SPA: "true" - ENABLE_POPOVERS: "true" - ANALYTICS_PROVIDER: "plausible" - BASE_URL: "localhost" - IGNORE_PATTERNS: "private,templates" - TYPOGRAPHY_HEADER: "Schibsted Grotesk" - TYPOGRAPHY_BODY: "Source Sans Pro" - TYPOGRAPHY_CODE: "IBM-Plex Mono" - - # Light Mode Colors - LIGHTMODE_LIGHT: "#faf8f8" - LIGHTMODE_LIGHTGRAY: "#e5e5e5" - LIGHTMODE_GRAY: "#bbbbbb" - LIGHTMODE_DARKGRAY: "#4e4e4e" - LIGHTMODE_DARK: "#2b2b2b" - LIGHTMODE_SECONDARY: "#284b63" - LIGHTMODE_TERTIARY: "#84a59d" - LIGHTMODE_HIGHLIGHT: "rgba(143,159,169,0.15)" - - # Dark Mode Colors - DARKMODE_LIGHT: "#161618" - DARKMODE_LIGHTGRAY: "#393639" - DARKMODE_GRAY: "#646464" - DARKMODE_DARKGRAY: "#4d4d4d" - DARKMODE_DARK: "#ebebec" - DARKMODE_SECONDARY: "#7b97aa" - DARKMODE_TERTIARY: "#84a59d" - DARKMODE_HIGHLIGHT: "rgba(143,159,169,0.15)" + QUARTZ_CONFIG_PATH: "/config/config.json" volumes: - /home/nathan/Repositories/modernleft-docs:/content + - ./config:/config - quartz-deps:/usr/share/nginx/html/node_modules volumes: diff --git a/entrypoint.sh b/entrypoint.sh index 7aaa527..bad4c4c 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,69 +1,45 @@ #!/bin/bash set -e -CONFIG_FILE="/usr/share/nginx/html/quartz.config.ts" -TEMP_FILE="${CONFIG_FILE}.tmp" - -replace_text() { - local search="$1" - local replace="$2" - # file var with default value - local file="${3:-$CONFIG_FILE}" - - if [[ -z "$search" || -z "$replace" ]]; then - echo "Error: Missing arguments" - return 1 +verify_config_exist() { + if [[ ! -f "/config/config.json" ]]; then + echo "Config file not found, copying default config..." + cp /usr/share/nginx/html/config.json /config/config.json fi - - # Modify a temporary file instead of the original - sed -e "s|${search}|${replace}|g" "$CONFIG_FILE" >"$TEMP_FILE" && mv "$TEMP_FILE" "$CONFIG_FILE" } -# Quartz Config -replace_text 'pageTitle: "🪴 Quartz 4.0",' "pageTitle: \"${PAGE_TITLE}\"," -replace_text 'enableSPA: true,' "enableSPA: ${ENABLE_SPA}," -replace_text 'enablePopovers: true,' "enablePopovers: ${ENABLE_POPOVERS}," -replace_text 'provider: "plausible",' "provider: \"${ANALYTICS_PROVIDER}\"," -replace_text 'baseUrl: "quartz.zhao.xyz",' "baseUrl: \"${BASE_URL}\"," -replace_text 'ignorePatterns: ["private", "templates"],' "ignorePatterns: [\"${IGNORE_PATTERNS//,/\", \"}\"]," -replace_text 'header: "Schibsted Grotesk",' "header: \"${TYPOGRAPHY_HEADER}\"," -replace_text 'body: "Source Sans Pro",' "body: \"${TYPOGRAPHY_BODY}\"," -replace_text 'code: "IBM-Plex Mono",' "code: \"${TYPOGRAPHY_CODE}\"," -replace_text 'light: "#faf8f8",' "light: \"${LIGHTMODE_LIGHT}\"," -replace_text 'lightgray: "#e5e5e5",' "lightgray: \"${LIGHTMODE_LIGHTGRAY}\"," -replace_text 'gray: "#bbbbbb",' "gray: \"${LIGHTMODE_GRAY}\"," -replace_text 'darkgray: "#4e4e4e",' "darkgray: \"${LIGHTMODE_DARKGRAY}\"," -replace_text 'dark: "#2b2b2b",' "dark: \"${LIGHTMODE_DARK}\"," -replace_text 'secondary: "#284b63",' "secondary: \"${LIGHTMODE_SECONDARY}\"," -replace_text 'tertiary: "#84a59d",' "tertiary: \"${LIGHTMODE_TERTIARY}\"," -replace_text 'highlight: "rgba(143, 159, 169, 0.15)",' "highlight: \"${LIGHTMODE_HIGHLIGHT}\"," -replace_text 'light: "#161618",' "light: \"${DARKMODE_LIGHT}\"," -replace_text 'lightgray: "#393639",' "lightgray: \"${DARKMODE_LIGHTGRAY}\"," -replace_text 'gray: "#646464",' "gray: \"${DARKMODE_GRAY}\"," -replace_text 'darkgray: "#4d4d4d",' "darkgray: \"${DARKMODE_DARKGRAY}\"," -replace_text 'dark: "#ebebec",' "dark: \"${DARKMODE_DARK}\"," -replace_text 'secondary: "#7b97aa",' "secondary: \"${DARKMODE_SECONDARY}\"," -replace_text 'tertiary: "#84a59d",' "tertiary: \"${DARKMODE_TERTIARY}\"," -replace_text 'highlight: "rgba(143, 159, 169, 0.15)",' "highlight: \"${DARKMODE_HIGHLIGHT}\"," -chown nginx:nginx "$CONFIG_FILE" +setup_cron() { + echo "${BUILD_SCHEDULE} cd /usr/share/nginx/html/content && git pull >/dev/null 2>&1 && cd /usr/share/nginx/html && npx quartz build >/dev/null 2>&1" >/etc/crontabs/root -echo "${BUILD_SCHEDULE} cd /usr/share/nginx/html/content && git pull >/dev/null 2>&1 && cd /usr/share/nginx/html && npx quartz build >/dev/null 2>&1" >/etc/crontabs/root + if [[ "$ENABLE_CRON" == "true" ]]; then + echo "Cron is enabled" + crond -b + else + echo "Cron is disabled" + fi +} -# NGINX script to sub variables in the template -/docker-entrypoint.d/20-envsubst-on-templates.sh +main() { + verify_config_exist + setup_cron -# ENABLE_CRON -if [[ "$ENABLE_CRON" == "true" ]]; then - echo "Cron is enabled" - crond -b -fi + chown -R nginx:nginx /usr/share/nginx/html + chown -R "${USER_ID}":"${GROUP_ID}" /content + chown -R "${USER_ID}":"${GROUP_ID}" /config -echo "Starting Quartz..." -echo "Installing dependencies..." -npm i >/dev/null + # NGINX script to sub variables in the template + echo "NGINX variable substitution..." + /docker-entrypoint.d/20-envsubst-on-templates.sh -echo "Building Quartz..." -npx quartz build + echo "Starting Quartz..." + echo "Installing dependencies..." + npm i >/dev/null -echo "Starting Nginx..." -exec nginx -g "daemon off;" + echo "Building Quartz..." + npx quartz build + + echo "Starting Nginx..." + exec nginx -g "daemon off;" +} + +main