init project

This commit is contained in:
Yusuf İpek
2021-06-30 21:38:54 +03:00
commit 3eb4a1e86f
20 changed files with 487 additions and 0 deletions
Executable
+203
View File
@@ -0,0 +1,203 @@
#!/usr/bin/make -f
BLOG := $(MAKE) -f $(lastword $(MAKEFILE_LIST)) --no-print-directory
ifneq ($(filter-out help,$(MAKECMDGOALS)),)
include config
endif
# The following can be configured in config
BLOG_DATE_FORMAT_INDEX ?= %x
BLOG_DATE_FORMAT ?= %x %X
BLOG_TITLE ?= blog
BLOG_DESCRIPTION ?= blog
BLOG_URL_ROOT ?= http://localhost/blog
BLOG_FEED_MAX ?= 20
BLOG_FEEDS ?= rss atom
BLOG_SRC ?= articles
.PHONY: help init build deploy clean
ARTICLES = $(shell git ls-tree HEAD --name-only -- $(BLOG_SRC)/ 2>/dev/null)
TAGFILES = $(patsubst $(BLOG_SRC)/%.md,tags/%,$(ARTICLES))
help:
$(info blogit init|build|deploy|clean)
init:
mkdir -p $(BLOG_SRC) data templates
printf '<!DOCTYPE html><html><head><title>$$TITLE</title></head><body>' > templates/header.html
printf '</body></html>' > templates/footer.html
printf '' > templates/index_header.html
printf '<p>Tags:' > templates/tag_list_header.html
printf '<a href="$$URL">$$NAME</a>' > templates/tag_entry.html
printf ', ' > templates/tag_separator.html
printf '</p>' > templates/tag_list_footer.html
printf '<h2>Articles</h2><ul>' > templates/article_list_header.html
printf '<li><a href="$$URL">$$DATE $$TITLE</a></li>' > templates/article_entry.html
printf '' > templates/article_separator.html
printf '</ul>' > templates/article_list_footer.html
printf '' > templates/index_footer.html
printf '' > templates/tag_index_header.html
printf '' > templates/tag_index_footer.html
printf '<h1>$$TITLE</h1>' > templates/article_header.html
printf '' > templates/article_footer.html
printf 'blog\n' > .git/info/exclude
build: blog/index.html tagpages $(patsubst $(BLOG_SRC)/%.md,blog/%.html,$(ARTICLES)) $(patsubst %,blog/%.xml,$(BLOG_FEEDS))
deploy: build
rsync -rLtvz $(BLOG_RSYNC_OPTS) blog/ data/ $(BLOG_REMOTE)
clean:
rm -rf blog tags
config:
printf 'BLOG_REMOTE:=%s\n' \
'$(shell printf "Blog remote (eg: host:/var/www/html): ">/dev/tty; head -n1)' \
> $@
tags/%: $(BLOG_SRC)/%.md
mkdir -p tags
grep -i '^; *tags:' "$<" | cut -d: -f2- | sed 's/ */\n/g' | sed '/^$$/d' | sort -u > $@
blog/index.html: $(ARTICLES) $(TAGFILES) $(addprefix templates/,$(addsuffix .html,header index_header tag_list_header tag_entry tag_separator tag_list_footer article_list_header article_entry article_separator article_list_footer index_footer footer))
mkdir -p blog
TITLE="$(BLOG_TITLE)"; \
export TITLE; \
envsubst < templates/header.html > $@; \
envsubst < templates/index_header.html >> $@; \
envsubst < templates/tag_list_header.html >> $@; \
first=true; \
for t in $(shell cat $(TAGFILES) | sort -u); do \
"$$first" || envsubst < templates/tag_separator.html; \
NAME="$$t" \
URL="@$$t.html" \
envsubst < templates/tag_entry.html; \
first=false; \
done >> $@; \
envsubst < templates/tag_list_footer.html >> $@; \
envsubst < templates/article_list_header.html >> $@; \
first=true; \
for f in $(ARTICLES); do \
printf '%s ' "$$f"; \
git log --diff-filter=A --date="format:%s $(BLOG_DATE_FORMAT_INDEX)" --pretty=format:'%ad%n' -- "$$f"; \
done | sort -k2nr | cut -d" " -f1,3- | while IFS=" " read -r FILE DATE; do \
"$$first" || envsubst < templates/article_separator.html; \
URL="`printf '%s' "\$$FILE" | sed 's,^$(BLOG_SRC)/\(.*\).md,\1,'`.html" \
DATE="$$DATE" \
TITLE="`head -n1 "\$$FILE" | sed -e 's/^# //g'`" \
envsubst < templates/article_entry.html; \
first=false; \
done >> $@; \
envsubst < templates/article_list_footer.html >> $@; \
envsubst < templates/index_footer.html >> $@; \
envsubst < templates/footer.html >> $@; \
blog/tag/%.html: $(ARTICLES) $(addprefix templates/,$(addsuffix .html,header tag_header index_entry tag_footer footer))
.PHONY: tagpages
tagpages: $(TAGFILES)
+$(BLOG) $(patsubst %,blog/@%.html,$(shell cat $(TAGFILES) | sort -u))
blog/@%.html: $(TAGFILES) $(addprefix templates/,$(addsuffix .html,header tag_index_header tag_list_header tag_entry tag_separator tag_list_footer article_list_header article_entry article_separator article_list_footer tag_index_footer footer))
mkdir -p blog
TITLE="Articles tagged $*"; \
TAGS="$*"; \
export TITLE; \
export TAGS; \
envsubst < templates/header.html > $@; \
envsubst < templates/tag_index_header.html >> $@; \
envsubst < templates/article_list_header.html >> $@; \
first=true; \
for f in $(shell grep -FH '$*' $(TAGFILES) | sed 's,^tags/\([^:]*\):.*,$(BLOG_SRC)/\1.md,'); do \
printf '%s ' "$$f"; \
git log --diff-filter=A --date="format:%s $(BLOG_DATE_FORMAT_INDEX)" --pretty=format:'%ad%n' -- "$$f"; \
done | sort -k2nr | cut -d" " -f1,3- | while IFS=" " read -r FILE DATE; do \
"$$first" || envsubst < templates/article_separator.html; \
URL="`printf '%s' "\$$FILE" | sed 's,^$(BLOG_SRC)/\(.*\).md,\1,'`.html" \
DATE="$$DATE" \
TITLE="`head -n1 "\$$FILE" | sed -e 's/^# //g'`" \
envsubst < templates/article_entry.html; \
first=false; \
done >> $@; \
envsubst < templates/article_list_footer.html >> $@; \
envsubst < templates/tag_index_footer.html >> $@; \
envsubst < templates/footer.html >> $@; \
blog/%.html: $(BLOG_SRC)/%.md $(addprefix templates/,$(addsuffix .html,header article_header article_footer footer))
mkdir -p blog
TITLE="$(shell head -n1 $<)"; \
export TITLE; \
AUTHOR="$(shell git log -n 1 --reverse --format="%cn" -- "$<")"; \
export AUTHOR; \
DATE_POSTED="$(shell git log --diff-filter=A --date="format:$(BLOG_DATE_FORMAT)" --pretty=format:'%ad' -- "$<")"; \
export DATE_POSTED; \
DATE_EDITED="$(shell git log -n 1 --date="format:$(BLOG_DATE_FORMAT)" --pretty=format:'%ad' -- "$<")"; \
export DATE_EDITED; \
TAGS="$(shell grep -i '^; *tags:' "$<" | cut -d: -f2- | paste -sd ',')"; \
export TAGS; \
envsubst < templates/header.html > $@; \
envsubst < templates/article_header.html >> $@; \
sed -e 1d \
-e '/^;/d' \
-e 's/&/\&amp;/g' \
-e 's/</\&lt;/g' \
-e 's/>/\&gt;/g' \
-e '/^```$$/{s,.*,,;x;p;/^<\/code>/d;s,.*,<pre><code>,;bT}' \
-e 'x;/<\/code>/{x;s,\$$,\&#36;,g;$$G;p;d};x' \
-e 's,\\\$$,\&#36;,g' \
-e '/^####/{s,^####,<h4>,;s,$$,</h4>,;H;s,.*,,;x;p;d}' \
-e '/^###/{s,^###,<h3>,;s,$$,</h3>,;H;s,.*,,;x;p;d}' \
-e '/^##/{s,^##,<h2>,;s,$$,</h2>,;H;s,.*,,;x;p;d}' \
-e '/^#/{s,^#,<h1>,;s,$$,</h1>,;H;s,.*,,;x;p;d}' \
-e 's,`\([^`]*\)`,<code>\1</code>,g' \
-e 's,\*\*\(\([^*<>][^*<>]*\*\?\)*\)\*\*,<b>\1</b>,g' \
-e 's,\*\([^*<>][^*<>]*\)\*,<i>\1</i>,g' \
-e 's,!\[\([^]]*\)\](\([^)]*\)),<img src="\2" alt="\1"/>,g' \
-e 's,\[\([^]]*\)\](\([^)]*\)),<a href="\2">\1</a>,g' \
-e '/^- /{s,^- ,<li>,;s,$$,</li>,;x;/^<\/ul>/{x;bL};p;s,.*,<ul>,;bT}' \
-e '/^[1-9][0-9]*\. /{s,^[0-9]*\. ,<li>,;s,$$,</li>,;x;/^<\/ol>/{x;bL};p;s,.*,<ol>,;bT}' \
-e '/^$$/{x;/^$$/d;p;d}' \
-e 'x;/^$$/{s,.*,<p>,;bT};x' \
-e ':L;$$G;p;d' \
-e ':T;p;:t;s,<\([^/>][^>]*\)>\(\(<[^/>][^>]*>\)*\),\2</\1>,;/<[^\/>]/bt;x;/^$$/{$${x;p};d};bL' \
"$<" | envsubst >> $@; \
envsubst < templates/article_footer.html >> $@; \
envsubst < templates/footer.html >> $@; \
blog/rss.xml: $(ARTICLES)
printf '<?xml version="1.0" encoding="UTF-8"?>\n<rss version="2.0">\n<channel>\n<title>%s</title>\n<link>%s</link>\n<description>%s</description>\n' \
"$(BLOG_TITLE)" "$(BLOG_URL_ROOT)" "$(BLOG_DESCRIPTION)" > $@
for f in $(ARTICLES); do \
printf '%s ' "$$f"; \
git log --diff-filter=A --date="format:%s %a, %d %b %Y %H:%M:%S %z" --pretty=format:'%ad%n' -- "$$f"; \
done | sort -k2nr | head -n $(BLOG_FEED_MAX) | cut -d" " -f1,3- | while IFS=" " read -r FILE DATE; do \
printf '<item>\n<title>%s</title>\n<link>%s</link>\n<guid>%s</guid>\n<pubDate>%s</pubDate>\n<description>%s</description>\n</item>\n' \
"`head -n 1 $$FILE`" \
"$(BLOG_URL_ROOT)/`basename $$FILE .md`.html" \
"$(BLOG_URL_ROOT)/`basename $$FILE .md`.html" \
"$$DATE" \
"`sed -n '1d;/^$$/{2{d;b};q};p' < $$FILE`"; \
done >> $@
printf '</channel>\n</rss>\n' >> $@
blog/atom.xml: $(ARTICLES)
printf '<?xml version="1.0" encoding="UTF-8"?>\n<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">\n<title type="text">%s</title>\n<subtitle type="text">%s</subtitle>\n<updated>%s</updated>\n<link rel="alternate" type="text/html" href="%s"/>\n<id>%s</id>\n<link rel="self" type="application/atom+xml" href="%s"/>\n' \
"$(BLOG_TITLE)" "$(BLOG_DESCRIPTION)" "$(shell date +%Y-%m-%dT%H:%M:%SZ)" "$(BLOG_URL_ROOT)" "$(BLOG_URL_ROOT)/atom.xml" "$(BLOG_URL_ROOT)/atom.xml" > $@
for f in $(ARTICLES); do \
printf '%s ' "$$f"; \
git log --diff-filter=A --date="format:%s %Y-%m-%dT%H:%M:%SZ" --pretty=format:'%ad %aN%n' -- "$$f"; \
done | sort -k2nr | head -n $(BLOG_FEED_MAX) | cut -d" " -f1,3- | while IFS=" " read -r FILE DATE AUTHOR; do \
printf '<entry>\n<title type="text">%s</title>\n<link rel="alternate" type="text/html" href="%s"/>\n<id>%s</id>\n<published>%s</published>\n<updated>%s</updated>\n<author><name>%s</name></author>\n<summary type="text">%s</summary>\n</entry>\n' \
"`head -n 1 $$FILE`" \
"$(BLOG_URL_ROOT)/`basename $$FILE .md`.html" \
"$(BLOG_URL_ROOT)/`basename $$FILE .md`.html" \
"$$DATE" \
"`git log -n 1 --date="format:%Y-%m-%dT%H:%M:%SZ" --pretty=format:'%ad' -- "$$FILE"`" \
"$$AUTHOR" \
"`sed -n '1d;/^$$/{2{d;b};q};p' < $$FILE`"; \
done >> $@
printf '</feed>\n' >> $@
+157
View File
@@ -0,0 +1,157 @@
.TH BLOG 1 blogit\-1.0
.SH NAME
blogit \- a small static blog generator
.SH SYNOPSIS
.B blogit
.RB [ init | build | deploy | clean ]
.SH DESCRIPTION
.B blogit
is a small static blog generator, using a markdown-like syntax and git capabilities.
For example, first posted and last edited dates are extracted from git history.
.SH GETTING STARTED
Run "blogit init" and follow the interactive configuration.
This will create the basic structure and initialize a git repository.
.SH STRUCTURE
Articles are created in the
.B articles
directory, using a markdown-like syntax (see
.BR SYNTAX ).
HTML templates (configurable chunks of HTML code that will be used for static page generation) are stored in the
.B templates
directory, and can be edited (see
.BR TEMPLATES ).
Additional data can be stored in the
.B data
directory and will be copied at the root of the website.
.SH WORKFLOW
The articles, templates and data can be created and edited offline.
To create a local version of the blog, run "blogit build".
It will be available in the
.B blog
directory, and the main page is index.html.
Note that only articles known to git will be created (this is to prevent unfinished articles to be published).
When its ready for publication, commit the changes to the git repository, and build the blog using "blogit build".
Then run "blogit deploy" to publish the site with
.BR rsync (1)
to the remote configured at the beginning.
.SH SYNTAX
The first line of the article text file is its title.
The next line can be blank, and will be skipped if that case.
Then the remaining of the file is in a markdown format, with the following formatting options:
.TP
.B Sections
Sections and subsections are defined by lines starting with one or several
.RB ' # ',
each indicating a new section level.
.TP
.B Paragraphs
Paragraphs are started with a blank line.
.TP
.B Bold, italics
Chunks enclosed in stars
.RB ' * '
are formatted in bold.
Chunks enclosed with two stars
.RB ' ** '
are formatted in bold.
.TP
.B Images
Images are inserted using the following syntax: "![alternate text](url)".
.TP
.B Links
Links are inserted using the following syntax: "[link text](url)".
.TP
.B Comments
Lines starting with a semi-colon are comments and are ignored.
It can be used to store metadata.
In particular, comments beginning with "tags:" indicate tags and are available in the templates in the TAGS variable.
.TP
.B Code blocks
Code blocks start and end with ``` (this marker must be on its own line).
The content is not formatted, and will appear as writter in the source file.
.TP
.B
Unordered lists
Each item starts with "- ".
.TP
.B
Ordered lists
Each item starts with "1. ", "2. " and so on.
The numbers are not checked, so any number can actually be used.
.SH TEMPLATES
Templates are small HTML code chunks that are used to build the blog pages.
Any variable reference
.RB ( $VARNAME )
is replaced with the corresponding environment variable value.
.SS Index page
The index page is built using the following templates:
- header.html;
- index_header.html;
- tag_list_header.html;
- tag_entry.html, for each tag;
- tag_separator.html, between each tag;
- tag_list_footer.html;
- article_list_header.html;
- article_entry.html, for each article entry;
- article_separator.html, between each article;
- article_list_footer.html;
- index_footer.html;
- footer.html.
The TITLE variable will contain "index".
In tag_entry, the following additional variables are available:
- URL, containing the (relative) URL of the tag index page;
- NAME, the tag name.
In article_entry, the following additional variables are available:
- URL, containing the (relative) URL of the article;
- DATE, the first publication date;
- TITLE, the title of the article.
.SS Article pages
Article pages are built from the following templates:
- header.html
- index_header.html
- (then the article file is formatted and inserted)
- index_footer.html
- footer.html
At all stages, the following variables are defined:
- TITLE, the title of the article;
- DATE_POSTED, the first publication date;
- DATE_EDITED, the last edit (commit) date;
- TAGS, the tags parsed from "tags:" comments.
+1
View File
@@ -0,0 +1 @@
BLOG_REMOTE:=/var/www/teknolojirehberleri.xyz
+79
View File
@@ -0,0 +1,79 @@
body {
background: #151515;
color: #ccc;
max-width: 800px;
margin: auto;
padding: 0 16px;
margin-bottom: 500px;
font-family: sans-serif;
}
a {
color: lightblue;
}
a:visited {
color: gray;
}
h1 {
text-align: center;
}
h2 {
color: tomato;
}
footer {
text-align: center;
}
img {
max-width: 600px;
width: 100%;
margin: auto;
display: block;
}
code {
overflow-wrap: break-word;
color: lime;
}
@media (prefers-color-scheme: light) {
body {
background: white;
color: black;
}
a {
color: blue;
}
a:visited {
color: purple;
}
h2 {
color: inherit;
}
code {
color: forestgreen;
}
}
@media print {
a[href] {
text-decoration: none;
color: black;
}
}
@media (min-width: 55em) {
#artlist {
column-count: 2;
}
}
@media (min-width: 100em) {
#artlist {
column-count: 3;
}
}
+1
View File
@@ -0,0 +1 @@
<li><a href="$URL">$TITLE</a></li>
+1
View File
@@ -0,0 +1 @@
</main><p><i>Yazının paylaşıldığı tarih: $DATE_POSTED, son düzenleme tarihi: $DATE_EDITED, yazar: $AUTHOR</i></p>
+1
View File
@@ -0,0 +1 @@
<h1>$TITLE</h1>
+1
View File
@@ -0,0 +1 @@
</ul>
+1
View File
@@ -0,0 +1 @@
<h2>Rehberler</h2><ul id=artlist>
View File
+12
View File
@@ -0,0 +1,12 @@
<footer>
<hr/>
<a href=".">ana sayfa</a>
<a href="./rss.xml">RSS</a>
<a href="./atom.xml">atom</a>
<br>
<p>All site content is in the Public Domain.</p>
<p>Sitedeki bütün içerikler kamu malıdır.</p>
<p><small>Kullanılan teknoloji:<a href="https://pedantic.software/git/blogit">blogit</a></small></p>
<p><small>Esinlenilen website:<a href="https://based.cooking">based cooking</a></small></p>
</footer>
</body></html>
+16
View File
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="icon"
type="image/png"
href="https://upload.wikimedia.org/wikipedia/commons/a/af/Tux.png"
/>
<link rel="stylesheet" href="./style.css" />
<title>$TITLE</title>
<meta name"description" content="Teknoloji rehberleri. Reklam ve
izleyici yok!" >
</head>
<body>
View File
+5
View File
@@ -0,0 +1,5 @@
<div class="banner">
<h1>⌨️ $TITLE 🖱️</h1>
<hr />
</div>
<p>Teknoloji rehberleri. Reklam ve izleyici yok!</p>
+1
View File
@@ -0,0 +1 @@
<a href="$URL">$NAME</a>
View File
+5
View File
@@ -0,0 +1,5 @@
<div class="banner">
<h1> ⌨️ $TITLE 🖱️ </h1>
<hr/>
</div>
<p><i>Etiketle rehber bulun:</i> <b>$TAGS</b></p>
+1
View File
@@ -0,0 +1 @@
</p>
+1
View File
@@ -0,0 +1 @@
<p>Tags:
+1
View File
@@ -0,0 +1 @@
,