blogs n shit

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

@ -3,6 +3,8 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
: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"]]
:eval-in-leiningen true)

@ -2,4 +2,6 @@
{: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>
<meta charset="UTF-8">
<!-- 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>
<body>
<header>
<nav>
&:nav
<a href="index.html">Index</a>
<a href="datblag/index.html">Datblad</a>
<a href="about.html">About</a>
</nav>
</header>
<main>
&:content
</main>
<aside>
<!--aside>
&:particle:aside
</aside>
</aside-->
</body>
</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"}
---
# Sweet home
&:last-blog-sites:datblag

@ -1,6 +1,7 @@
(ns equilibrium.blog
(:require [clojure.java.io :as io]
[clojure.string :as string]))
[clojure.string :as string]
[equilibrium.core :as core]))
(defn index-file [dir-name root]
(io/file (str root "/blogs/" dir-name "/index.md")))
@ -18,17 +19,13 @@
(analysed-blog-dir-name "hudel")
(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)]
(merge {:ix ix
:blog-dir-name blog-dir-name}
(update-in analysed-index
[:metadata :page-size]
#(or % 10)))))
{:ix ix
:blog-dir-name blog-dir-name}))
(comment
(blog-index-file "datblag")
(blog-config "datblag"))
(config "datblag"))
(defn target-root [config root]
(str root
@ -36,22 +33,39 @@
(:blog-dir-name config)))
(comment
(blog-target-root {:blog-dir-name "hudel"})
(blog-sites-dir "datblag"))
(target-root {:blog-dir-name "hudel"}))
(defn site->target-file [config root site]
(io/file (str (target-root config root)
"/"
(:filename site)
(core/clean-name (:filename site))
".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]
(let [index-file (io/file (str (target-root config
output-root)
"/index.html"))]
(io/make-parents 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
:let [target (site->target-file config output-root site)]]
(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]
[clojure.string :as string]
[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))
(def input-root "resources/page")
(def output-root "target/page")
(defn filename [file]
(-> file
.toPath
.getFileName
.toString))
(defn is-md-file? [file]
(.endsWith (filename file) ".md"))
(.endsWith (core/filename file) ".md"))
(defn md-files [root]
(->> root
@ -29,14 +25,10 @@
(defn index-template []
(slurp (str input-root "/index.html")))
(defn clean-name [filename]
(let [end (- (count filename) 3)
start (inc (or (string/index-of filename "+") -1))]
(subs filename start end)))
(comment
(defn navcode [sites]
(let [sorted-sites (sort-by #(filename %) sites)
clean-file-name-fn #(clean-name (filename %))
(let [sorted-sites (sort-by #(core/filename %) sites)
clean-file-name-fn #(core/clean-name (core/filename %))
nav-line-fn #(str "<li>"
"<a href=\""
(clean-file-name-fn %)
@ -47,27 +39,18 @@
(reduce #(str %1 (nav-line-fn %2))
""
sorted-sites)
"</ol>")))
"</ol>"))))
(defn site-destination [filename]
(str output-root
"/"
(clean-name filename)
(core/clean-name filename)
".html"))
(comment
(site-destination "01+allo.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---")
(defn page-metadata [content]
@ -91,28 +74,102 @@
(page-content "---\nDINGE\n---\nwulle")
(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]
(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
(particles-in-content "asd &particle:hullu"))
(defn now-str []
(.toString (LocalDateTime/now)))
(defn particle-content [particle]
(-> (str input-root "/particles/" particle ".md")
io/file
slurp
render-markdown))
(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 [context html page]
(defn fill-in-placeholders [html page]
(let [simple (-> html
(string/replace #"&:nav" (:navcode context ""))
;; (string/replace #"&:nav" (:navcode context ""))
(string/replace #"&:content" (:content page ""))
(string/replace #"&:title" (get-in page [:metadata :title] ""))
(string/replace #"&:generated-at" (now-str)))
particles (particles-in-content simple)]
(reduce (fn [result particle]
(string/replace result
particles (particles-in-content simple)
last-blog-sites (last-blog-sites-in-content simple)
particle-fn (fn [result particle]
(string/replace
result
(first particle)
(particle-content (second particle))))
simple
particles)))
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
(fill-in-placeholders {:navcode "hhh"}
@ -123,19 +180,13 @@
{:content "dinge"})
)
(defn write-sites [context template sites]
(defn write-sites [template sites]
(doseq [site sites
:let [translated (fill-in-placeholders context template site)
filename (filename (:file site))
:let [translated (fill-in-placeholders template site)
filename (core/filename (:file site))
destination (site-destination filename)]]
(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]
(doseq [file (file-seq dir)]
@ -150,40 +201,43 @@
io/file
.listFiles
(filter #(.isDirectory %))
(sort-by #(filename %))))
(sort-by #(core/filename %))))
(comment
(blog-dirs))
(defn render-blog [context template dir]
(let [dir-name (filename dir)
(defn render-blog [template dir]
(let [dir-name (core/filename dir)
index-file (blog/index-file dir-name input-root)
config (merge (blog/config dir-name
(analysed-page index-file))
config (merge (blog/config dir-name)
{:dir dir})
blog-sites (->> (blog/sites-dir dir-name input-root)
md-files
(map analysed-page))]
blog-sites (blog-sites dir-name)]
(blog/write-files config
output-root
blog-sites
(partial fill-in-placeholders
context template))
template))
config))
(defn copy-resources []
(fs/copy-dir (str input-root
"/resources")
(str output-root
"/resources")))
(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]
(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"))
rendered-sites (map analysed-page sites)
template (index-template)
context {:navcode (navcode sites)}]
(write-sites context template rendered-sites)
(for [blog-dir (blog-dirs)]
(render-blog context template blog-dir))))
template (index-template)]
(write-sites template rendered-sites)
(doseq [blog-dir (blog-dirs)]
(render-blog template blog-dir))))
(comment
(render {})
(doall (navcode (md-files "resources/user/sites"))))
(render {}))

Loading…
Cancel
Save