blogs n shit

master
Josha von Gizycki 6 years ago
parent 2ed52864c5
commit aeb7f51deb

@ -3,6 +3,8 @@
:url "http://example.com/FIXME" :url "http://example.com/FIXME"
:license {:name "Eclipse Public License" :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"} :url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[com.velisco/clj-ftp "0.3.12"] :dependencies [[org.clojure/clojure "1.10.0"]
[me.raynes/fs "1.4.6"]
[com.velisco/clj-ftp "0.3.12"]
[markdown-clj "1.0.5"]] [markdown-clj "1.0.5"]]
:eval-in-leiningen true) :eval-in-leiningen true)

@ -2,4 +2,6 @@
{:title "first entry"} {:title "first entry"}
--- ---
# JAHOOO # FIRST
hallo welt

@ -0,0 +1,11 @@
---
{:title "second entry"}
---
# SECOND
Inhalt und so
<blink>
hallo welt wieder

@ -0,0 +1,7 @@
---
{:title "third entry"}
---
# THIRD
hallo welt wieder wieder

@ -3,17 +3,23 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<!-- generated at &:generated-at --> <!-- generated at &:generated-at -->
<title>Equilibrium page &:title</title> <title>&:title - joshavg</title>
<base href="file:///home/josha/projekte/equilibrium/target/page/">
<link rel="stylesheet" href="resources/style.css">
</head> </head>
<body> <body>
<nav> <header>
&:nav <nav>
</nav> <a href="index.html">Index</a>
<a href="datblag/index.html">Datblad</a>
<a href="about.html">About</a>
</nav>
</header>
<main> <main>
&:content &:content
</main> </main>
<aside> <!--aside>
&:particle:aside &:particle:aside
</aside> </aside-->
</body> </body>
</html> </html>

@ -0,0 +1,78 @@
a:link, a:visited {
text-decoration: none;
color: blue;
}
a:hover, a:active {
text-decoration: underline;
}
header {
padding: 1em;
margin-bottom: 1em;
}
header h1 {
margin: 0;
margin-bottom: .2em;
font-size: 2em;
}
main h1 {
font-size: 1.7em;
}
main h2 {
font-size: 1.4em;
}
main h3 {
font-size: 1.2em;
}
nav a {
margin-right: 1em;
}
main {
padding-left: 1em;
}
article {
padding-left: 1em;
}
#content .article-title {
margin-left: -.5em;
margin-bottom: .3em;
}
#content .article-title:before {
content: "â–» ";
}
#content > .article-title~time {
margin-bottom: 1em;
}
#content blockquote {
background-color: #f5f5f5;
padding: .3em;
padding-left: .6em;
margin-left: 0;
}
#content blockquote p {
margin: 0;
}
time {
font-style: italic;
}
@media only screen and (min-width: 1000px) {
body {
margin-left: 20%;
margin-right: 20%;
}
}

@ -0,0 +1,19 @@
# Impressum - auch Pflichtangaben genannt
Josha von Gizycki
Beckmannweg 13
38642 Goslar
<p>ma<span style='display: none;'>wollolol</span>il&commat;jo<span style="display:none;">tüdel</span>&#x73;&#x68;&#x61;<span style="display:none ;">press alt+f4 to get handgrenades</span>vg.<span style="display:none;">merop</span>de</p>
# Copyright
Alle Inhalte meiner Seiten unterliegen - soweit nicht anders gekennzeichnet - meinem Copyright. Es ist nicht gestattet, Texte oder Grafiken meiner Seite ohne meine Einwilligung ganz oder in Teilen zu verwenden und zu veröffentlichen. Zu diesem Thema wird auf die einschlägigen Urteile hierzu verwiesen.
# Haftungshinweis
Trotz sorgfältiger inhaltlicher Kontrolle übernehme ich keine Haftung für die Inhalte externer Links. Für den Inhalt der verlinkten Seiten sind ausschließlich deren Betreiber verantwortlich.
# Datenschutzerklärung
Der Webserver schreibt Logdateien mit den Zugriffen und den IP-Adressen der Zugreifer. Da es auf dieser Seite keine Benutzerkonten und keine Tracking-Cookies o.ä. gibt, werden diese Logdateien nicht als personenbezogen betrachtet.

@ -2,3 +2,5 @@
{:title "Home"} {:title "Home"}
--- ---
# Sweet home # Sweet home
&:last-blog-sites:datblag

@ -1,6 +1,7 @@
(ns equilibrium.blog (ns equilibrium.blog
(:require [clojure.java.io :as io] (:require [clojure.java.io :as io]
[clojure.string :as string])) [clojure.string :as string]
[equilibrium.core :as core]))
(defn index-file [dir-name root] (defn index-file [dir-name root]
(io/file (str root "/blogs/" dir-name "/index.md"))) (io/file (str root "/blogs/" dir-name "/index.md")))
@ -18,17 +19,13 @@
(analysed-blog-dir-name "hudel") (analysed-blog-dir-name "hudel")
(analysed-blog-dir-name "4711+wudel")) (analysed-blog-dir-name "4711+wudel"))
(defn config [dir-name analysed-index] (defn config [dir-name]
(let [[ix blog-dir-name] (analysed-blog-dir-name dir-name)] (let [[ix blog-dir-name] (analysed-blog-dir-name dir-name)]
(merge {:ix ix {:ix ix
:blog-dir-name blog-dir-name} :blog-dir-name blog-dir-name}))
(update-in analysed-index
[:metadata :page-size]
#(or % 10)))))
(comment (comment
(blog-index-file "datblag") (config "datblag"))
(blog-config "datblag"))
(defn target-root [config root] (defn target-root [config root]
(str root (str root
@ -36,22 +33,39 @@
(:blog-dir-name config))) (:blog-dir-name config)))
(comment (comment
(blog-target-root {:blog-dir-name "hudel"}) (target-root {:blog-dir-name "hudel"}))
(blog-sites-dir "datblag"))
(defn site->target-file [config root site] (defn site->target-file [config root site]
(io/file (str (target-root config root) (io/file (str (target-root config root)
"/" "/"
(:filename site) (core/clean-name (:filename site))
".html"))) ".html")))
(defn index-file-content [blog-dir-name sites]
(str "<ol>"
(reduce #(str %1
"<li>"
"<a href=\""
(:link %2)
"\">"
(-> %2 :metadata :title)
"</a>"
"</li>")
""
sites)
"</ol>"))
(defn write-files [config output-root sites fill-in-fn] (defn write-files [config output-root sites fill-in-fn]
(let [index-file (io/file (str (target-root config (let [index-file (io/file (str (target-root config
output-root) output-root)
"/index.html"))] "/index.html"))]
(io/make-parents index-file) (io/make-parents index-file)
(spit index-file (spit index-file
(fill-in-fn config))) (fill-in-fn (assoc config
:content
(index-file-content
(:blog-dir-name config)
sites)))))
(doseq [site sites (doseq [site sites
:let [target (site->target-file config output-root site)]] :let [target (site->target-file config output-root site)]]
(spit target (spit target

@ -0,0 +1,13 @@
(ns equilibrium.core
(:require [clojure.string :as string]))
(defn clean-name [filename]
(let [end (- (count filename) 3)
start (inc (or (string/index-of filename "+") -1))]
(subs filename start end)))
(defn filename [file]
(-> file
.toPath
.getFileName
.toString))

@ -2,20 +2,16 @@
(:require [clojure.java.io :as io] (:require [clojure.java.io :as io]
[clojure.string :as string] [clojure.string :as string]
[markdown.core :as md] [markdown.core :as md]
[equilibrium.blog :as blog]) [equilibrium.blog :as blog]
[equilibrium.core :as core]
[me.raynes.fs :as fs])
(:import java.time.LocalDateTime)) (:import java.time.LocalDateTime))
(def input-root "resources/page") (def input-root "resources/page")
(def output-root "target/page") (def output-root "target/page")
(defn filename [file]
(-> file
.toPath
.getFileName
.toString))
(defn is-md-file? [file] (defn is-md-file? [file]
(.endsWith (filename file) ".md")) (.endsWith (core/filename file) ".md"))
(defn md-files [root] (defn md-files [root]
(->> root (->> root
@ -29,45 +25,32 @@
(defn index-template [] (defn index-template []
(slurp (str input-root "/index.html"))) (slurp (str input-root "/index.html")))
(defn clean-name [filename] (comment
(let [end (- (count filename) 3) (defn navcode [sites]
start (inc (or (string/index-of filename "+") -1))] (let [sorted-sites (sort-by #(core/filename %) sites)
(subs filename start end))) clean-file-name-fn #(core/clean-name (core/filename %))
nav-line-fn #(str "<li>"
(defn navcode [sites] "<a href=\""
(let [sorted-sites (sort-by #(filename %) sites) (clean-file-name-fn %)
clean-file-name-fn #(clean-name (filename %)) ".html\">"
nav-line-fn #(str "<li>" (clean-file-name-fn %)
"<a href=\"" "</a></li>")]
(clean-file-name-fn %) (str "<ol>"
".html\">" (reduce #(str %1 (nav-line-fn %2))
(clean-file-name-fn %) ""
"</a></li>")] sorted-sites)
(str "<ol>" "</ol>"))))
(reduce #(str %1 (nav-line-fn %2))
""
sorted-sites)
"</ol>")))
(defn site-destination [filename] (defn site-destination [filename]
(str output-root (str output-root
"/" "/"
(clean-name filename) (core/clean-name filename)
".html")) ".html"))
(comment (comment
(site-destination "01+allo.md") (site-destination "01+allo.md")
(site-destination "aside.md")) (site-destination "aside.md"))
(defn particle-content [particle]
(-> (str input-root "/particles/" particle ".md")
io/file
slurp
render-markdown))
(comment
(particle-content "aside"))
(def metadata-regex #"^---\n(.+?)\n---") (def metadata-regex #"^---\n(.+?)\n---")
(defn page-metadata [content] (defn page-metadata [content]
@ -91,28 +74,102 @@
(page-content "---\nDINGE\n---\nwulle") (page-content "---\nDINGE\n---\nwulle")
(page-content "aiaiaiai")) (page-content "aiaiaiai"))
(defn now-str []
(.toString (LocalDateTime/now)))
(defn file->relpath [file]
(let [fullpath (-> file .toPath .toString)
root-pos (string/index-of fullpath input-root)]
(subs fullpath
(+ root-pos (count input-root) 1))))
(defn analysed-page [file]
(let [content (slurp file)
relpath (file->relpath file)
blog? (string/starts-with? relpath "blogs/")
blog-dir (when blog?
(-> relpath io/file .toPath
(.subpath 1 2) .toString))
filename (core/clean-name (core/filename file))
link (if blog?
(str blog-dir "/" filename ".html")
(str filename ".html"))]
{:file file
:relpath relpath
:blog? blog?
:link link
:filename (core/filename file)
:content (-> content page-content render-markdown)
:metadata (page-metadata content)}))
(defn particles-in-content [content] (defn particles-in-content [content]
(re-seq #"&:particle:([^\s]+)" content)) (re-seq #"&:particle:([^\s<]+)" content))
(defn last-blog-sites-in-content [content]
(re-seq #"&:last-blog-sites:([^\s<]+)" content))
(comment (comment
(particles-in-content "asd &particle:hullu")) (particles-in-content "asd &particle:hullu"))
(defn now-str [] (defn particle-content [particle]
(.toString (LocalDateTime/now))) (-> (str input-root "/particles/" particle ".md")
io/file
slurp
render-markdown))
(defn fill-in-placeholders [context html page] (defn blog-sites [dir-name]
(->> (blog/sites-dir dir-name input-root)
md-files
(map analysed-page)
(sort-by :filename)))
(comment
(particle-content "aside"))
(defn blog-sites-preview [blog-name]
(reduce (fn [res site]
(let [content (:content site)
divider-pos (string/index-of content "<p><blink></p>")
length (count content)
end (or divider-pos length)
pre-content (subs content 0 end)
article-link (str "<a href=\""
(:link site)
"\">↪</a>")]
(str res
"<article>"
pre-content
"<p class=\"article-link\">"
article-link
"</p>"
"</article>")))
""
(->> blog-name
blog-sites
(take-last 5)
reverse)))
(defn fill-in-placeholders [html page]
(let [simple (-> html (let [simple (-> html
(string/replace #"&:nav" (:navcode context "")) ;; (string/replace #"&:nav" (:navcode context ""))
(string/replace #"&:content" (:content page "")) (string/replace #"&:content" (:content page ""))
(string/replace #"&:title" (get-in page [:metadata :title] "")) (string/replace #"&:title" (get-in page [:metadata :title] ""))
(string/replace #"&:generated-at" (now-str))) (string/replace #"&:generated-at" (now-str)))
particles (particles-in-content simple)] particles (particles-in-content simple)
(reduce (fn [result particle] last-blog-sites (last-blog-sites-in-content simple)
(string/replace result particle-fn (fn [result particle]
(first particle) (string/replace
(particle-content (second particle)))) result
simple (first particle)
particles))) (particle-content (second particle))))
blog-sites-fn (fn [result [match-str blog-name]]
(string/replace
result
match-str
(blog-sites-preview blog-name)))]
(as-> simple $
(reduce particle-fn $ particles)
(reduce blog-sites-fn $ last-blog-sites))))
(comment (comment
(fill-in-placeholders {:navcode "hhh"} (fill-in-placeholders {:navcode "hhh"}
@ -123,19 +180,13 @@
{:content "dinge"}) {:content "dinge"})
) )
(defn write-sites [context template sites] (defn write-sites [template sites]
(doseq [site sites (doseq [site sites
:let [translated (fill-in-placeholders context template site) :let [translated (fill-in-placeholders template site)
filename (filename (:file site)) filename (core/filename (:file site))
destination (site-destination filename)]] destination (site-destination filename)]]
(spit destination translated))) (spit destination translated)))
(defn analysed-page [file]
(let [content (slurp file)]
{:file file
:filename (filename file)
:content (-> content page-content render-markdown)
:metadata (page-metadata content)}))
(defn clear-dir [dir] (defn clear-dir [dir]
(doseq [file (file-seq dir)] (doseq [file (file-seq dir)]
@ -150,40 +201,43 @@
io/file io/file
.listFiles .listFiles
(filter #(.isDirectory %)) (filter #(.isDirectory %))
(sort-by #(filename %)))) (sort-by #(core/filename %))))
(comment (comment
(blog-dirs)) (blog-dirs))
(defn render-blog [context template dir] (defn render-blog [template dir]
(let [dir-name (filename dir) (let [dir-name (core/filename dir)
index-file (blog/index-file dir-name input-root) index-file (blog/index-file dir-name input-root)
config (merge (blog/config dir-name config (merge (blog/config dir-name)
(analysed-page index-file))
{:dir dir}) {:dir dir})
blog-sites (->> (blog/sites-dir dir-name input-root) blog-sites (blog-sites dir-name)]
md-files
(map analysed-page))]
(blog/write-files config (blog/write-files config
output-root output-root
blog-sites blog-sites
(partial fill-in-placeholders (partial fill-in-placeholders
context template)) template))
config)) config))
(defn copy-resources []
(fs/copy-dir (str input-root
"/resources")
(str output-root
"/resources")))
(defn render (defn render
"Renders all markdown pages under resources/user using the structure in resources/user/structure to target/page" "Renders all markdown pages under resources/user using the structure in
resources/user/structure to target/page"
[project] [project]
(clear-dir (io/file output-root)) (clear-dir (io/file output-root))
(io/make-parents output-root) (io/make-parents (str output-root "/a"))
(copy-resources)
(let [sites (md-files (str input-root "/sites")) (let [sites (md-files (str input-root "/sites"))
rendered-sites (map analysed-page sites) rendered-sites (map analysed-page sites)
template (index-template) template (index-template)]
context {:navcode (navcode sites)}] (write-sites template rendered-sites)
(write-sites context template rendered-sites) (doseq [blog-dir (blog-dirs)]
(for [blog-dir (blog-dirs)] (render-blog template blog-dir))))
(render-blog context template blog-dir))))
(comment (comment
(render {}) (render {}))
(doall (navcode (md-files "resources/user/sites"))))

Loading…
Cancel
Save