Browse Source

Implemented The basic prototype

tags/0.0.1
Vincent Truchseß 1 year ago
parent
commit
3a57839dc7
8 changed files with 124 additions and 30 deletions
  1. +3
    -0
      .gitignore
  2. +2
    -2
      CHANGELOG.md
  3. +1
    -1
      README.md
  4. +1
    -1
      doc/intro.md
  5. +5
    -4
      project.clj
  6. +0
    -20
      src/asciiblogtor/core.clj
  7. +110
    -0
      src/proton/core.clj
  8. +2
    -2
      test/proton/core_test.clj

+ 3
- 0
.gitignore View File

@@ -10,3 +10,6 @@ pom.xml.asc
/.nrepl-port
.hgignore
.hg/
/site/*
/input/*
*.adoc

+ 2
- 2
CHANGELOG.md View File

@@ -20,5 +20,5 @@ All notable changes to this project will be documented in this file. This change
- Files from the new template.
- Widget maker public API - `make-widget-sync`.

[Unreleased]: https://github.com/your-name/asciiblogtor/compare/0.1.1...HEAD
[0.1.1]: https://github.com/your-name/asciiblogtor/compare/0.1.0...0.1.1
[Unreleased]: https://github.com/your-name/proton/compare/0.1.1...HEAD
[0.1.1]: https://github.com/your-name/proton/compare/0.1.0...0.1.1

+ 1
- 1
README.md View File

@@ -1,3 +1,3 @@
# Asciiblogtor
# Proton

A simple, **asciidoctor** based static blog generator written in **Clojure**.

+ 1
- 1
doc/intro.md View File

@@ -1,3 +1,3 @@
# Introduction to asciiblogtor
# Introduction to proton

TODO: write [great documentation](http://jacobian.org/writing/what-to-write/)

+ 5
- 4
project.clj View File

@@ -1,9 +1,10 @@
(defproject asciiblogtor "0.1.0-SNAPSHOT"
(defproject proton "0.1.0-SNAPSHOT"
:description "An asciidoctor based blog generator"
:url "https://git.fyber.space/vincent/asciiblogtor"
:url "https://git.fyber.space/vincent/proton"
:license {:name "GPL-3.0"
:url "https://www.gnu.org/licenses/gpl-3.0.html"}
:dependencies [
[org.clojure/clojure "1.10.0"]
[org.asciidoctor/asciidoctorj "2.0.0"]]
:repl-options {:init-ns asciiblogtor.core})
[org.asciidoctor/asciidoctorj "2.0.0"]
[hiccup "1.0.5"]]
:repl-options {:init-ns proton.core})

+ 0
- 20
src/asciiblogtor/core.clj View File

@@ -1,20 +0,0 @@
(ns asciiblogtor.core
(:import org.asciidoctor.Asciidoctor))

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))

+ 110
- 0
src/proton/core.clj View File

@@ -0,0 +1,110 @@
(ns proton.core
(:use hiccup.core)
(:import (org.asciidoctor Asciidoctor$Factory))
(:require [clojure.java.io :as io]))

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

(def outdir (io/file "site"))

(def adoc-factory (Asciidoctor$Factory/create))

(defn adoc-load-raw [file]
(bean (.loadFile adoc-factory (io/file file) {})))

(defn adoc-load
"Load adoc content from file and a target-dir and return a map with it's data"
[file]
(let [file (io/file file)
filename (.getName (io/file file))
raw-post (bean (.loadFile adoc-factory (io/file file) {}))
post-from-raw (fn [post]
{:title (:title post)
:date (get-in post [:attributes "date"] "")
:content (:content post)})]
(into (post-from-raw raw-post) {:filename filename})))

(defn add-url [post target-dir]
(into post {:url (str (io/file target-dir (clojure.string/replace
(:filename post)
#"\.adoc$"
".html")))}))

(defn write-page
"Writes content to a page"
[url content]
(spit (io/file outdir url)
(html [:body
[:header
[:nav
[:a {:href "index.html"} "Home"]
[:a {:href "about.html"} "About"]
[:a {:href "archive.html"} "Archive"]
[:a {:href "contact.html"} "Contact"]]]
[:main {:role "main"} content]
[:footer {:role "footer"} "TODO"]])))

(defn write-post
([post] (write-post post (:url post)))
([post url]
(write-page url
[:span
[:span {:class "title"}
[:h1 (:title post)]
[:span {:class "datestamp"} (:date post)]]
[:span {:class "content"} (:content post)]])
post))

(defn compile-posts
"Reads posts from dir or source-dir, writes post-pages to dir or outdir and
returns a vector of posts"
([] (compile-posts "posts"))
([dir] (compile-posts dir dir))
([source-dir target-dir]
(let [all-files (.listFiles (io/file source-dir))
adoc-files (filter #(re-matches #".+\.adoc$" (.getName (io/file %))) all-files)
posts (map #(add-url % target-dir) (map adoc-load adoc-files))]
(map write-post posts))))

(defn post-listentry [post]
[:li {:class "listentry"}
[:a {:class "listtitle" :href (:url post)} (:title post)]
[:span {:class "listdatestamp"} (:date post)]])

(defn gen-postlist
([posts n] (gen-postlist (take n posts)))
([posts]
(let [entries (map post-listentry posts)]
(into [:div {:class "postlist"}] entries))))

(defn compile-page [file target]
(write-page target (:content (adoc-load file))))

(defn write-archive [posts target]
(write-page target (gen-postlist posts)))

(defn write-index [posts]
(write-page "index.html"
[:span
[:div {:class "index-content"}
(:content (adoc-load "index.adoc"))]
[:div {:class "postlist"}
(gen-postlist posts 10)]]))

(defn generate-site []
(let [posts (compile-posts)]
(compile-page "about.adoc" "about.html")
(compile-page "contact.adoc" "contact.html")
(write-archive posts "archive.html")
(write-index posts)))

test/asciiblogtor/core_test.clj → test/proton/core_test.clj View File

@@ -1,6 +1,6 @@
(ns asciiblogtor.core-test
(ns proton.core-test
(:require [clojure.test :refer :all]
[asciiblogtor.core :refer :all]))
[proton.core :refer :all]))

(deftest a-test
(testing "FIXME, I fail."

Loading…
Cancel
Save