Improve readme

This commit is contained in:
Yann Esposito (Yogsototh) 2024-01-20 00:08:31 +01:00
parent 652f5d1744
commit 87385bda86
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
3 changed files with 148 additions and 116 deletions

48
README.org Normal file
View file

@ -0,0 +1,48 @@
#+title: Readme
#+author: Yann Esposito
#+created: [2024-01-19 Fri]
* =statyk=
A short program whose goal is to build a static websites as naturally as possible.
The main concept is about keeping in sync a directory of files and their
respective content.
Mainly we would like the following:
For every file in ~_src~ directory create an associated generated file in ~_site~.
For example:
#+begin_src
_src/ ------------> _site/
index.md -- pandoc --> index.html
about.org -- pandoc --> about.html
yolo.html ---- cp ----> yolo.html
post/01.md -- pandoc --> post/01.html
post/02.org -- pandoc --> post/02.html
img/logo.png - imgoptim -> img/logo.webp
css/main.sass - less+min -> css/main.css
js/main.js - minimize -> js/main.js
#+end_src
Another mechanism is building meta files.
#+begin_src
phase 1:
_src/ ------------> _site/
...
post/01.md -- pandoc --> post/01.html
post/02.org -- pandoc --> post/02.html
..
post/42.org -- pandoc --> post/42.html
phase 2:
_site/ \ _site/
index.md | ...
post/01.html | sitemap.html
... > rss.xml
post/20.html | archive.html
... |
post/42.html /
#+end_src

View file

@ -43,89 +43,6 @@
<main id="content">
<h2>Articles</h2>
$body$
<h3>Archives from my previous dead blog</h3>
<ul>
<li><span class="pubDate">2016-10-01</span> <span class="post-title"><a href="/Scratch/en/blog/Helping-avoid-Haskell-Success/">Tips in avoiding Haskell Success at all cost</a></span></li>
<li><span class="pubDate">2016-05-06</span> <span class="post-title"><a href="/Scratch/en/blog/Haskell-Tutorials--a-tutorial/">Haskell Tutorials, a tutorial</a></span></li>
<li><span class="pubDate">2014-12-07</span> <span class="post-title"><a href="/Scratch/en/blog/Vim-as-IDE/">Vim as IDE</a></span></li>
<li><span class="pubDate">2014-08-16</span> <span class="post-title"><a href="/Scratch/en/blog/Safer-Haskell-Install/">Safer Haskell Install</a></span></li>
<li><span class="pubDate">2013-11-14</span> <span class="post-title"><a href="/Scratch/en/blog/Holy-Haskell-Starter/">Holy Haskell Project Starter</a></span></li>
<li><span class="pubDate">2013-10-09</span> <span class="post-title"><a href="/Scratch/en/blog/Parsec-Presentation/">Parsec Presentation</a></span></li>
<li><span class="pubDate">2013-08-06</span> <span class="post-title"><a href="/Scratch/en/blog/Rational-Web-Framework-Choice/">Rational Web Framework Choice</a></span></li>
<li><span class="pubDate">2013-03-16</span> <span class="post-title"><a href="/Scratch/en/blog/Hakyll-setup/">Hakyll setup</a></span></li>
<li><span class="pubDate">2013-03-14</span> <span class="post-title"><a href="/Scratch/en/blog/Social-link-the-right-way/">Social link the right way</a></span></li>
<li><span class="pubDate">2012-12-12</span> <span class="post-title"><a href="/Scratch/en/blog/Category-Theory-Presentation/">Category Theory Presentation</a></span></li>
<li><span class="pubDate">2012-06-15</span> <span class="post-title"><a href="/Scratch/en/blog/Haskell-OpenGL-Mandelbrot/">Haskell Progressive Example</a></span></li>
<li><span class="pubDate">2012-02-08</span> <span class="post-title"><a href="/Scratch/en/blog/Haskell-the-Hard-Way/">Learn Haskell Fast and Hard</a></span></li>
<li><span class="pubDate">2012-02-02</span> <span class="post-title"><a href="/Scratch/en/blog/Typography-and-the-Web/">Typography and the Web</a></span></li>
<li><span class="pubDate">2012-01-15</span> <span class="post-title"><a href="/Scratch/en/blog/Yesod-tutorial-for-newbies/">Haskell web programming</a></span></li>
<li><span class="pubDate">2011-10-20</span> <span class="post-title"><a href="/Scratch/en/blog/SVG-and-m4-fractals/">Increase the power of deficient languages.</a></span></li>
<li><span class="pubDate">2011-10-04</span> <span class="post-title"><a href="/Scratch/en/blog/Yesod-excellent-ideas/">Yesod excellent ideas</a></span></li>
<li><span class="pubDate">2011-09-28</span> <span class="post-title"><a href="/Scratch/en/blog/Higher-order-function-in-zsh/">Higher order function in zsh</a></span></li>
<li><span class="pubDate">2011-09-28</span> <span class="post-title"><a href="/Scratch/en/blog/programming-language-experience/">Programming Language Experience</a></span></li>
<li><span class="pubDate">2011-08-25</span> <span class="post-title"><a href="/Scratch/en/blog/Learn-Vim-Progressively/">Learn Vim Progressively</a></span></li>
<li><span class="pubDate">2011-08-17</span> <span class="post-title"><a href="/Scratch/en/blog/A-more-convenient-diff/">A more convenient diff</a></span></li>
<li><span class="pubDate">2011-07-10</span> <span class="post-title"><a href="/Scratch/en/blog/Haskell-Mandelbrot/">ASCII Haskell Mandelbrot</a></span></li>
<li><span class="pubDate">2011-05-18</span> <span class="post-title"><a href="/Scratch/en/blog/Password-Management/">40 character's passwords</a></span></li>
<li><span class="pubDate">2011-04-20</span> <span class="post-title"><a href="/Scratch/en/blog/2011-04-20-Now-hosted-on-github/">Now hosted on github</a></span></li>
<li><span class="pubDate">2011-01-03</span> <span class="post-title"><a href="/Scratch/en/blog/2011-01-03-Why-I-sadly-won-t-use-coffeescript/">Why I won't use CoffeeScript (sadly)</a></span></li>
<li><span class="pubDate">2011-01-01</span> <span class="post-title"><a href="/Scratch/en/blog/2011-01-03-Happy-New-Year/">Happy New Year</a></span></li>
<li><span class="pubDate">2010-10-26</span> <span class="post-title"><a href="/Scratch/en/blog/2010-10-26-LaTeX-like-macro-and-markdown/">LaTeX like macro for markdown</a></span></li>
<li><span class="pubDate">2010-10-14</span> <span class="post-title"><a href="/Scratch/en/blog/2010-10-14-Fun-with-wav/">Fun with wav</a></span></li>
<li><span class="pubDate">2010-10-10</span> <span class="post-title"><a href="/Scratch/en/blog/2010-10-10-Secure-eMail-on-Mac-in-few-steps/">Secure eMail on Mac in few steps</a></span></li>
<li><span class="pubDate">2010-10-06</span> <span class="post-title"><a href="/Scratch/en/blog/2010-10-06-New-Blog-Design-Constraints/">New Blog Design Constraints</a></span></li>
<li><span class="pubDate">2010-09-02</span> <span class="post-title"><a href="/Scratch/en/blog/2010-09-02-Use-git-to-calculate-trusted-mtimes/">Use git to calculate trusted mtimes</a></span></li>
<li><span class="pubDate">2010-09-02</span> <span class="post-title"><a href="/Scratch/en/blog/2010-09-02-base64-and-sha1-on-iPhone/">base64 and sha1 on iPhone</a></span></li>
<li><span class="pubDate">2010-08-31</span> <span class="post-title"><a href="/Scratch/en/blog/2010-08-31-send-mail-from-command-line-with-attached-file/">send mail from command line with attached file</a></span></li>
<li><span class="pubDate">2010-08-23</span> <span class="post-title"><a href="/Scratch/en/blog/2010-08-23-Now-heberged-on-heroku/">Now hosted by heroku</a></span></li>
<li><span class="pubDate">2010-08-11</span> <span class="post-title"><a href="/Scratch/en/blog/2010-07-09-Indecidabilities/">Undecidabilities (part 1)</a></span></li>
<li><span class="pubDate">2010-07-31</span> <span class="post-title"><a href="/Scratch/en/blog/2010-07-31-New-style-after-holidays/">New style after holidays</a></span></li>
<li><span class="pubDate">2010-07-07</span> <span class="post-title"><a href="/Scratch/en/blog/2010-07-07-CSS-rendering-problems-by-navigator/">Do not use CSS gradient with Chrome</a></span></li>
<li><span class="pubDate">2010-07-05</span> <span class="post-title"><a href="/Scratch/en/blog/2010-07-05-Cappuccino-and-Web-applications/">Cappuccino vs jQuery</a></span></li>
<li><span class="pubDate">2010-06-19</span> <span class="post-title"><a href="/Scratch/en/blog/2010-06-19-jQuery-popup-the-easy-way/">jQuery popup the easy way</a></span></li>
<li><span class="pubDate">2010-06-17</span> <span class="post-title"><a href="/Scratch/en/blog/2010-06-17-hide-yourself-to-analytics/">Hide Yourself to your Analytics</a></span></li>
<li><span class="pubDate">2010-06-17</span> <span class="post-title"><a href="/Scratch/en/blog/2010-06-17-track-events-with-google-analytics/">Track Events with Google Analytics</a></span></li>
<li><span class="pubDate">2010-06-15</span> <span class="post-title"><a href="/Scratch/en/blog/2010-06-15-Get-my-blog-engine/">Get my blog engine</a></span></li>
<li><span class="pubDate">2010-06-14</span> <span class="post-title"><a href="/Scratch/en/blog/2010-06-14-multi-language-choices/">multi language choices</a></span></li>
<li><span class="pubDate">2010-05-24</span> <span class="post-title"><a href="/Scratch/en/blog/2010-05-24-Trees--Pragmatism-and-Formalism/">Trees; Pragmatism and Formalism</a></span></li>
<li><span class="pubDate">2010-05-19</span> <span class="post-title"><a href="/Scratch/en/blog/2010-05-19-How-to-cut-HTML-and-repair-it/">How to repair a cutted XML?</a></span></li>
<li><span class="pubDate">2010-05-17</span> <span class="post-title"><a href="/Scratch/en/blog/2010-05-17-at-least-this-blog-revive/">I live again!</a></span></li>
<li><span class="pubDate">2010-03-23</span> <span class="post-title"><a href="/Scratch/en/blog/2010-03-23-Encapsulate-git/">Encapsulate git</a></span></li>
<li><span class="pubDate">2010-03-22</span> <span class="post-title"><a href="/Scratch/en/blog/2010-03-22-Git-Tips/">Git Tips</a></span></li>
<li><span class="pubDate">2010-02-23</span> <span class="post-title"><a href="/Scratch/en/blog/2010-02-23-When-regexp-is-not-the-best-solution/">When regexp is not the best solution</a></span></li>
<li><span class="pubDate">2010-02-18</span> <span class="post-title"><a href="/Scratch/en/blog/2010-02-18-split-a-file-by-keyword/">split a file by keyword</a></span></li>
<li><span class="pubDate">2010-02-16</span> <span class="post-title"><a href="/Scratch/en/blog/2010-02-16-All-but-something-regexp--2-/">Pragmatic Regular Expression Exclude (2)</a></span></li>
<li><span class="pubDate">2010-02-15</span> <span class="post-title"><a href="/Scratch/en/blog/2010-02-15-All-but-something-regexp/">Pragmatic Regular Expression Exclude</a></span></li>
<li><span class="pubDate">2010-01-12</span> <span class="post-title"><a href="/Scratch/en/blog/2010-01-12-antialias-font-in-Firefox-under-Ubuntu/">antialias font in Firefox under Ubuntu</a></span></li>
<li><span class="pubDate">2010-01-04</span> <span class="post-title"><a href="/Scratch/en/blog/2010-01-04-Change-default-shell-on-Mac-OS-X/">Change default shell on Mac OS X</a></span></li>
<li><span class="pubDate">2009-12-14</span> <span class="post-title"><a href="/Scratch/en/blog/2009-12-14-Git-vs--Bzr/">Git vs. Bzr</a></span></li>
<li><span class="pubDate">2009-12-06</span> <span class="post-title"><a href="/Scratch/en/blog/2009-12-06-iphone-call-filter/">iphone call filter</a></span></li>
<li><span class="pubDate">2009-11-12</span> <span class="post-title"><a href="/Scratch/en/blog/2009-11-12-Git-for-n00b/">Git for n00b</a></span></li>
<li><span class="pubDate">2009-10-30</span> <span class="post-title"><a href="/Scratch/en/blog/2009-10-30-How-to-handle-evil-IE/">How to handle evil IE</a></span></li>
<li><span class="pubDate">2009-10-28</span> <span class="post-title"><a href="/Scratch/en/blog/2009-10-28-custom-website-synchronisation-with-mobileme--2-/">custom website synchronisation with mobileme (2)</a></span></li>
<li><span class="pubDate">2009-10-26</span> <span class="post-title"><a href="/Scratch/en/blog/2009-10-Wait-to-hide-a-menu-in-jQuery/">Menu waiting to hide himself</a></span></li>
<li><span class="pubDate">2009-10-23</span> <span class="post-title"><a href="/Scratch/en/blog/2009-10-launch-daemon-from-command-line/">launch daemon from command line</a></span></li>
<li><span class="pubDate">2009-10-22</span> <span class="post-title"><a href="/Scratch/en/blog/2009-10-Focus-vs-Minimalism/">Focus &gt; Minimalism</a></span></li>
<li><span class="pubDate">2009-10-13</span> <span class="post-title"><a href="/Scratch/en/blog/2009-10-untaught-git-usage/">Untaught Git usage</a></span></li>
<li><span class="pubDate">2009-10-03</span> <span class="post-title"><a href="/Scratch/en/blog/2009-10-How-to-preload-your-site-with-style/">How to preload your site with style</a></span></li>
<li><span class="pubDate">2009-09-28</span> <span class="post-title"><a href="/Scratch/en/blog/2009-09-Disqus-versus-Intense-Debate--Why-I-switched-/">Disqus versus Intense Debate (Why I switched)</a></span></li>
<li><span class="pubDate">2009-09-23</span> <span class="post-title"><a href="/Scratch/en/blog/2009-09-jQuery-Tag-Cloud/">jQuery Tag Cloud</a></span></li>
<li><span class="pubDate">2009-09-22</span> <span class="post-title"><a href="/Scratch/en/blog/2009-09-replace-all-except-some-part/">replace all except some part</a></span></li>
<li><span class="pubDate">2009-09-17</span> <span class="post-title"><a href="/Scratch/en/blog/11_Load_Disqus_Asynchronously/">Load Disqus Asynchronously</a></span></li>
<li><span class="pubDate">2009-09-11</span> <span class="post-title"><a href="/Scratch/en/blog/09_Why_I_didn-t_keep_whosamung-us/">Why I didn't keep whos.amung.us</a></span></li>
<li><span class="pubDate">2009-09-11</span> <span class="post-title"><a href="/Scratch/en/blog/10_Synchronize_Custom_WebSite_with_mobileMe/">Synchronize Custom WebSite with mobileMe</a></span></li>
<li><span class="pubDate">2009-09-07</span> <span class="post-title"><a href="/Scratch/en/blog/08_Configure_ssh_to_listen_the_port_443_on_Snow_Leopard/">ssh to Listen 443 on Snow Leopard</a></span></li>
<li><span class="pubDate">2009-09-06</span> <span class="post-title"><a href="/Scratch/en/blog/07_Screensaver_compilation_option_for_Snow_Leopard/">Screensaver compilation option for Snow Leopard&copy;</a></span></li>
<li><span class="pubDate">2009-08-18</span> <span class="post-title"><a href="/Scratch/en/blog/06_How_I_use_git/">Git for self</a></span></li>
<li><span class="pubDate">2009-08-17</span> <span class="post-title"><a href="/Scratch/en/blog/05_git_create_remote_branch/">Git remote branch creation</a></span></li>
<li><span class="pubDate">2009-08-15</span> <span class="post-title"><a href="/Scratch/en/blog/04_drm/">DRM are EVIL</a></span></li>
<li><span class="pubDate">2009-08-04</span> <span class="post-title"><a href="/Scratch/en/blog/03_losthighway/">A try to demystify 'Lost Highway'</a></span></li>
<li><span class="pubDate">2009-07-22</span> <span class="post-title"><a href="/Scratch/en/blog/02_ackgrep/">Better than Grep</a></span></li>
<li><span class="pubDate">2008-10-10</span> <span class="post-title"><a href="/Scratch/en/blog/01_nanoc/">Nanoc</a></span></li>
</ul>
</main>
<footer id="postamble" class="status">
<div class="content">

133
statyk
View file

@ -55,11 +55,18 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@"
(def cli-options
[])
(defn p [& args]
(println (apply format args)))
(defn pr [& args]
(print (apply format args))
(flush))
(defn pr-err!
"Print on std error"
[s & args]
(binding [*out* *err*]
(println (apply format s args))))
(apply p s args)))
(defn err!
[s & args]
@ -75,11 +82,15 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@"
nil)))
(defn is-newer?
"returns true if file-1 is newer than file-2"
"returns true if file-1 is newer than file-2 or if file-2 does not exists"
[f1 f2]
(let [[t1 t2] (mapv #(fs/file-time->millis (fs/get-attribute % "basic:lastModifiedTime"))
[f1 f2])]
(< t2 t1)))
(when-not (fs/exists? f1)
(err! "File '%s' does not exists..." f1))
(if (fs/exists? f2)
(let [[t1 t2] (mapv #(fs/file-time->millis (fs/get-attribute % "basic:lastModifiedTime"))
[f1 f2])]
(< t2 t1))
true))
(defn serve-dest-dir-handler
[request]
@ -122,31 +133,77 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@"
[org]
;; TODO search for options in the org mode file
;; (seek org #"^#+options:")
)
nil)
(defn find-md-mode-options
[md]
;; TODO search for options in the metadata of the md file
;; (seek org #"^#+options:")
nil)
(defn log-cmd
([cmd]
(when-let [error-msg (seq (:err (apply sh cmd)))]
(pr-err! "\n\n%s\n" error-msg)))
([msg cmd]
(when msg
(pr msg))
(if-let [error-msg (seq (:err (apply sh cmd)))]
(do
(p " [failed!]")
(pr-err! "\n\n%s\n" error-msg))
(p " [done]"))))
(defn org->html
[src-file dst-file]
(let [options (find-org-mode-options src-file)]
(sh "pandoc"
(when (:toc options) "--toc")
(when-let [tpl (:template options)]
(format "--template=%s" tpl))
"--lua-filter=.statik/org-links-to-html.lua"
"--lua-filter=.statik/img-to-webp.lua"
"--lua-filter=.statik/metas.lua"
"--mathml"
"--from" "org"
"--to" "html5"
"--standalone"
src-file
"--output"
dst-file)))
(let [options (find-org-mode-options src-file)
cmd (filter some?
["pandoc"
(when (:toc options)
"--toc")
(if-let [tpl (:template options)]
(format "--template=%s" tpl)
(format "--template=_templates/post.html"))
"--lua-filter=.statyk/org-links-to-html.lua"
"--lua-filter=.statyk/img-to-webp.lua"
"--lua-filter=.statyk/metas.lua"
"--mathml"
"--from" "org"
"--to" "html5"
"--standalone"
src-file
"--output"
dst-file])]
(log-cmd (format "Generating %s" dst-file) cmd)))
(defn md->html
[src-file dst-file]
(let [options (find-md-mode-options src-file)
cmd (filter some?
["pandoc"
(when (:toc options) "--toc")
(if-let [tpl (:template options)]
(format "--template=%s" tpl)
(format "--template=_templates/post.html"))
"--lua-filter=.statyk/img-to-webp.lua"
"--lua-filter=.statyk/metas.lua"
"--mathml"
"--from" "markdown"
"--to" "html5"
"--standalone"
src-file
"--output"
dst-file])]
(log-cmd (format "Generating %s" dst-file) cmd)))
(defn build-html
[ext src-file dst-file]
;; TODO PANDOC then minify
(sh "pandoc" )
)
(case ext
"org" (org->html src-file dst-file)
"md" (md->html src-file dst-file)
(p "no support for %s" ext)))
(defn build-css
[src-file dst-file]
;; TODO cless or copy then minify
@ -159,19 +216,28 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@"
(defn build
"Table with specific commands per type of file"
[src-file dst-file ext]
[src-path dst-path ext]
(cond
(html-src-type? ext) (build-html ext src-file dst-file)
(css-src-type? ext) (build-css src-file dst-file)
(img-src-type? ext) (build-img src-file dst-file)
:else (fs/copy src-file dst-file)))
(html-src-type? ext) (build-html ext src-path dst-path)
(css-src-type? ext) (build-css src-path dst-path)
(img-src-type? ext) (build-img src-path dst-path)
:else
(if (fs/directory? src-path)
(do
(p "Creating directory %s" dst-path)
(fs/create-dirs dst-path))
(do
(p "Copying to %s" dst-path)
(fs/copy src-path dst-path)))))
(defn generate-static-files
[]
(doseq [src-file (file-seq (io/file (:source-directory config)))]
(let [{:keys [ext dst-file]} (dst-file-name-and-ext src-file)]
(when (is-newer? src-file dst-file)
(build src-file dst-file ext)))))
(doseq [src-path (map str (file-seq (io/file (:source-directory config))))]
(prn src-path)
(let [{:keys [ext dst-path] :as r} (dst-file-name-and-ext src-path)]
(when (is-newer? src-path dst-path)
(prn r)
(build src-path dst-path ext)))))
(defn show-help
[]
@ -241,7 +307,8 @@ exec clojure $OPTS -Sdeps "$DEPS" -M "$0" "$@"
(do-command "init" options))
(future (do-command "serve" options))
(do-command "watch" options)))))
(do-command "watch" options))))
(shutdown-agents))
(apply -main *command-line-args*)