55
66set -euo pipefail
77
8+ # Configuration
9+ BLOG_TITLE=" ${BLOG_TITLE:- Noob Notes} "
10+ BLOG_AUTHOR=" ${BLOG_AUTHOR:- bytenoob} "
11+ BLOG_EMAIL=" ${BLOG_EMAIL:- noreply@ example.com} "
12+ INCREMENTAL_BUILD=" ${INCREMENTAL_BUILD:- false} "
13+
814# Source configuration if available
915if [ -f " .blogrc" ]; then
1016 # shellcheck source=/dev/null
@@ -18,6 +24,11 @@ NC='\033[0m'
1824
1925echo -e " ${GREEN} Building blog...${NC} "
2026
27+ # Show incremental build option if not enabled
28+ if [ " $INCREMENTAL_BUILD " != " true" ]; then
29+ echo -e " ${YELLOW} Tip:${NC} Use INCREMENTAL_BUILD=true $0 to skip unchanged files"
30+ fi
31+
2132# Get version numbers for cache busting based on file modification time
2233CSS_VERSION=$( stat -c %Y static/css/blog.css 2> /dev/null || stat -f %m static/css/blog.css 2> /dev/null || echo " 1" )
2334JS_VERSION=$( stat -c %Y static/js/blog.js 2> /dev/null || stat -f %m static/js/blog.js 2> /dev/null || echo " 1" )
@@ -40,6 +51,7 @@ if emacs --batch \
4051 ;; Set user info (use environment variables for security)
4152 (setq user-full-name (or (getenv \" BLOG_AUTHOR\" ) \" bytenoob\" ))
4253 (setq user-mail-address (or (getenv \" BLOG_EMAIL\" ) \" noreply@example.com\" ))
54+ (setq blog-title (or (getenv \" BLOG_TITLE\" ) \" Noob Notes\" ))
4355
4456 ;; Load org and ox-publish
4557 (require 'org)
@@ -94,12 +106,21 @@ if emacs --batch \
94106 ;; If htmlize fails to load, continue without syntax highlighting
95107 (message \" Warning: htmlize not available, syntax highlighting disabled\" )))
96108
109+ ;; Common HTML head content
110+ (defun blog/html-head ()
111+ (concat \" <link rel=\\\" icon\\\" type=\\\" image/svg+xml\\\" href=\\\" /static/favicon.svg\\\" >
112+ <link rel=\\\" preconnect\\\" href=\\\" https://fonts.googleapis.com\\\" >
113+ <link rel=\\\" preconnect\\\" href=\\\" https://fonts.gstatic.com\\\" crossorigin>
114+ <link href=\\\" https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap\\\" rel=\\\" stylesheet\\\" >
115+ <link rel=\\\" stylesheet\\\" type=\\\" text/css\\\" href=\\\" /static/css/blog.css?v=\" (or (getenv \" CSS_VERSION\" ) \" 1\" ) \"\\\" />
116+ <script src=\\\" /static/js/blog.js?v=\" (or (getenv \" JS_VERSION\" ) \" 1\" ) \"\\\" defer></script>\" ))
117+
97118 ;; Custom HTML preamble and postamble
98119 (defun blog/preamble (info)
99120 (concat
100121 \" <header class=\\\" site-header\\\" >\"
101122 \" <div class=\\\" container\\\" >\"
102- \" <h1 class=\\\" site-title\\\" ><a href=\\\" /\\\" >Noob Notes </a></h1>\"
123+ \" <h1 class=\\\" site-title\\\" ><a href=\\\" /\\\" >\" blog-title \" </a></h1>\"
103124 \" <nav class=\\\" site-nav\\\" >\"
104125 \" <a href=\\\" /\\\" >Home</a>\"
105126 \" <a href=\\\" /about.html\\\" >About</a>\"
@@ -130,16 +151,31 @@ if emacs --batch \
130151 (goto-char (point-min))
131152 (re-search-forward \" ^#\\\\ +DRAFT:\\\\ s-*\\\\ (true\\\\ |t\\\\ |yes\\\\ )\" nil t)))
132153
133- ;; Custom publishing function that skips drafts
154+ ;; Function to check if file needs rebuilding
155+ (defun blog/needs-rebuild-p (org-file html-file)
156+ \" Check if ORG-FILE needs to be rebuilt by comparing with HTML-FILE.\"
157+ (or (not (file-exists-p html-file))
158+ (file-newer-than-file-p org-file html-file)
159+ (not (string= (getenv \" INCREMENTAL_BUILD\" ) \" true\" ))))
160+
161+ ;; Custom publishing function that skips drafts and unchanged files
134162 (defun blog/publish-to-html (plist filename pub-dir)
135- \" Publish an org file to HTML, but skip if it's a draft.\"
163+ \" Publish an org file to HTML, but skip if it's a draft or unchanged .\"
136164 (unless (blog/is-draft-p filename)
137- (org-html-publish-to-html plist filename pub-dir)))
165+ (let* ((html-file (concat pub-dir
166+ (file-name-sans-extension
167+ (file-name-nondirectory filename))
168+ \" .html\" )))
169+ (if (blog/needs-rebuild-p filename html-file)
170+ (progn
171+ (message \" Building: %s\" filename)
172+ (org-html-publish-to-html plist filename pub-dir))
173+ (message \" Skipping unchanged: %s\" filename)))))
138174
139175 ;; Custom sitemap function to exclude author and draft posts
140176 (defun blog/sitemap-function (title list)
141177 \" Generate sitemap as an Org file without author metadata and draft posts.\"
142- (concat \" #+TITLE: Noob Notes \\ n\"
178+ (concat \" #+TITLE: \" blog-title \" \\ n\"
143179 \" #+AUTHOR:\\ n\"
144180 \" #+OPTIONS: author:nil toc:nil num:nil h:0\\ n\\ n\"
145181 (org-list-to-org list)))
@@ -157,12 +193,7 @@ if emacs --batch \
157193 :with-toc t
158194 :with-author t
159195 :with-date t
160- :html-head ,(concat \" <link rel=\\\" icon\\\" type=\\\" image/svg+xml\\\" href=\\\" /static/favicon.svg\\\" >
161- <link rel=\\\" preconnect\\\" href=\\\" https://fonts.googleapis.com\\\" >
162- <link rel=\\\" preconnect\\\" href=\\\" https://fonts.gstatic.com\\\" crossorigin>
163- <link href=\\\" https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap\\\" rel=\\\" stylesheet\\\" >
164- <link rel=\\\" stylesheet\\\" type=\\\" text/css\\\" href=\\\" /static/css/blog.css?v=\" (or (getenv \" CSS_VERSION\" ) \" $CSS_VERSION \" ) \"\\\" />
165- <script src=\\\" /static/js/blog.js?v=\" (or (getenv \" JS_VERSION\" ) \" $JS_VERSION \" ) \"\\\" defer></script>\" )
196+ :html-head ,(blog/html-head)
166197 :html-preamble blog/preamble
167198 :html-postamble blog/postamble
168199 :html-head-include-default-style nil
@@ -190,12 +221,7 @@ if emacs --batch \
190221 :with-toc t
191222 :with-author t
192223 :with-date t
193- :html-head ,(concat \" <link rel=\\\" icon\\\" type=\\\" image/svg+xml\\\" href=\\\" /static/favicon.svg\\\" >
194- <link rel=\\\" preconnect\\\" href=\\\" https://fonts.googleapis.com\\\" >
195- <link rel=\\\" preconnect\\\" href=\\\" https://fonts.gstatic.com\\\" crossorigin>
196- <link href=\\\" https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap\\\" rel=\\\" stylesheet\\\" >
197- <link rel=\\\" stylesheet\\\" type=\\\" text/css\\\" href=\\\" /static/css/blog.css?v=\" (or (getenv \" CSS_VERSION\" ) \" $CSS_VERSION \" ) \"\\\" />
198- <script src=\\\" /static/js/blog.js?v=\" (or (getenv \" JS_VERSION\" ) \" $JS_VERSION \" ) \"\\\" defer></script>\" )
224+ :html-head ,(blog/html-head)
199225 :html-preamble blog/preamble
200226 :html-postamble blog/postamble
201227 :html-head-include-default-style nil
@@ -224,10 +250,14 @@ if emacs --batch \
224250
225251 # Show build statistics
226252 if [ -d " public" ]; then
227- POST_COUNT=$( find public -name " *.html" -not -name " index.html" | wc -l)
253+ POST_COUNT=$( find public -name " *.html" -not -name " index.html" -not -name " index-cn.html " | wc -l)
228254 TOTAL_SIZE=$( du -sh public | cut -f1)
229255 echo -e " ${GREEN} Generated:${NC} $POST_COUNT posts"
230256 echo -e " ${GREEN} Total size:${NC} $TOTAL_SIZE "
257+
258+ if [ " $INCREMENTAL_BUILD " = " true" ]; then
259+ echo -e " ${GREEN} Mode:${NC} Incremental build"
260+ fi
231261 fi
232262else
233263 echo -e " ${YELLOW} Build completed with warnings${NC} "
0 commit comments