Browse Source

external templates

edited readme
tags/0.0.1
Vincent Truchseß 1 year ago
parent
commit
b6a68b3723
10 changed files with 119 additions and 52 deletions
  1. +1
    -0
      .gitignore
  2. +30
    -0
      README.md
  3. +3
    -1
      project.clj
  4. +1
    -0
      site.clj
  5. +5
    -1
      src/proton/core.clj
  6. +25
    -0
      src/proton/site.clj
  7. +4
    -50
      src/proton/templates.clj
  8. +39
    -0
      templates/default/default.clj
  9. +5
    -0
      templates/default/index.clj
  10. +6
    -0
      templates/default/post.clj

+ 1
- 0
.gitignore View File

@@ -13,3 +13,4 @@ pom.xml.asc
/site/*
/input/*
*.adoc
/templates/custom

+ 30
- 0
README.md View File

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

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

---

**WARNING:** This is still a beta-release. It is already usable for simple
websites but there is still work to do, such as implementing tests ans proper
Documentation.

---

## System requirements

You need a working clojure-environment as well as leiningen.

## Usage

Clone the git-repository

```
git clone https://git.fyber.space/vincent/proton
cd proton
```

Add `site.clj` to your `.gitignore`

```
echo "/src/proton/site.clj" >> .gitignore
```

Now, edit the site.clj to your needs. You may add own functions and templates as you wish.
You may place your own templates in `templates/custom`.

+ 3
- 1
project.clj View File

@@ -8,4 +8,6 @@
[org.asciidoctor/asciidoctorj "2.0.0"]
[hiccup "1.0.5"]
[org.clojure/data.xml "0.0.8"]]
:repl-options {:init-ns proton.core})
:repl-options {:init-ns proton.core}
:source-paths ["src"]
:main proton.core)

+ 1
- 0
site.clj View File

@@ -0,0 +1 @@
src/proton/site.clj

+ 5
- 1
src/proton/core.clj View File

@@ -1,7 +1,8 @@
(ns proton.core
(:require [proton.templates :as tpl])
(:require [proton.writers :as wr])
(:require [proton.rss :as rss]))
(:require [proton.rss :as rss])
(:require [proton.site :as site]))

;; 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
@@ -35,3 +36,6 @@
(wr/write-archive-page t posts "archive.html")
(wr/write-index-with-posts t tpl/default-index-template posts)
(rss/write-feed posts testopts)))

(defn -main [ & args ]
(site/site))

+ 25
- 0
src/proton/site.clj View File

@@ -0,0 +1,25 @@
(ns proton.site
(:require [proton.templates :as tpl])
(:require [proton.writers :as wr])
(:require [proton.rss :as rss]))

(defn site []
;;This function gets loaded at runtime into proton.core. The available namespaces are
;;aliassed as follows:
;; proton.templates tpl
;; proton.writers wr
;; proton.rss rss
(let [t proton.templates/default-template
posts (wr/compile-posts t tpl/default-post-template)
rss-opts {:title "Test"
:link "https://test.foo"
:host "test.foo"
:description "This is a test feed"
:rss-link "https://test.foo/rss.xml"
:author "MEeeeee"
:max-items 20}]
(wr/compile-page t "about.adoc" "about.html")
(wr/compile-page t "contact.adoc" "contact.html")
(wr/write-archive-page t posts "archive.html")
(wr/write-index-with-posts t tpl/default-index-template posts)
(rss/write-feed posts rss-opts)))

+ 4
- 50
src/proton/templates.clj View File

@@ -1,55 +1,9 @@
(ns proton.templates)

(defn default-template [author date content title extras]
[:html {:lang "en"}
[:head
[:meta {:charset "utf-8"}]
[:meta {:http-equiv "x-ua-compatible"
:content "ie=edge"}]
[:meta {:name "viewport"
:content "width=device-width, init-scale=1"}]
[:title title]
[:link {:rel "stylesheet"
:href (str (:base-url extras) "css/default.css")}]
[:link {:rel "icon"
:type "image/png"
:href (str (:base-url extras) "favicon.png")}]]
[:body
[:header
[:div {:class "logo"}
[:a {:href (:base-url extras)}
[:img {:src (str (:base-url extras) "logo.png")}]]]
(into [:nav]
(map (fn [[url label]]
[:a {:href (str (:base-url extras) url)} label])
[["index.html" "Home"]
["about.html" "About"]
["archive.html" "Archive"]
["contact.html" "Contact"]]))]
[:main {:role "main"}
[:h1 title]
content]
[:footer
[:a {:href (str (:base-url extras) "contact.html")
:style "float: left; padding-right: 8px;"}
"Impress"]
[:a {:href (str (:base-url extras) "rss.xml")
:style "float: left;"}
"RSS feed"]
"Site proudly generated by"
[:a {:href "https://git.fyber.space/vincent/proton"}
"Proton"]]]])
(def default-template (load-file "templates/default/default.clj"))

(defn default-index-template [author date content title extras]
[:span
[:div {:class "index-content"}
content]
(:postlist extras)])
(def default-index-template (load-file "templates/default/index.clj"))

(defn default-post-template [author date content title extras]
[:article
[:section {:class "header"}
"Posted on " date
(if author (str " by " author))]
[:section content]])
(def default-post-template (load-file "templates/default/post.clj"))

(def template-from-file load-file)

+ 39
- 0
templates/default/default.clj View File

@@ -0,0 +1,39 @@
(fn [author date content title extras]
[:html {:lang "en"}
[:head
[:meta {:charset "utf-8"}]
[:meta {:http-equiv "x-ua-compatible"
:content "ie=edge"}]
[:meta {:name "viewport"
:content "width=device-width, init-scale=1"}]
[:title title]
[:link {:rel "stylesheet"
:href (str (:base-url extras) "css/default.css")}]
[:link {:rel "icon"
:type "image/png"
:href (str (:base-url extras) "favicon.png")}]]
[:body
[:header
[:div {:class "logo"}
[:a {:href (:base-url extras)}
[:img {:src (str (:base-url extras) "logo.png")}]]]
(into [:nav]
(map (fn [[url label]]
[:a {:href (str (:base-url extras) url)} label])
[["index.html" "Home"]
["about.html" "About"]
["archive.html" "Archive"]
["contact.html" "Contact"]]))]
[:main {:role "main"}
[:h1 title]
content]
[:footer
[:a {:href (str (:base-url extras) "contact.html")
:style "float: left; padding-right: 8px;"}
"Impress"]
[:a {:href (str (:base-url extras) "rss.xml")
:style "float: left;"}
"RSS feed"]
"Site proudly generated by"
[:a {:href "https://git.fyber.space/vincent/proton"}
"Proton"]]]])

+ 5
- 0
templates/default/index.clj View File

@@ -0,0 +1,5 @@
(fn [author date content title extras]
[:span
[:div {:class "index-content"}
content]
(:postlist extras)])

+ 6
- 0
templates/default/post.clj View File

@@ -0,0 +1,6 @@
(fn [author date content title extras]
[:article
[:section {:class "header"}
"Posted on " date
(if author (str " by " author))]
[:section content]])

Loading…
Cancel
Save