commit 3eb4a1e86fed18dc77f7d56d5928951d1d4d212b Author: Yusuf İpek Date: Wed Jun 30 21:38:54 2021 +0300 init project diff --git a/blogit b/blogit new file mode 100755 index 0000000..cbbc787 --- /dev/null +++ b/blogit @@ -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 '$$TITLE' > templates/header.html + printf '' > templates/footer.html + printf '' > templates/index_header.html + printf '

Tags:' > templates/tag_list_header.html + printf '$$NAME' > templates/tag_entry.html + printf ', ' > templates/tag_separator.html + printf '

' > templates/tag_list_footer.html + printf '

Articles

' > templates/article_list_footer.html + printf '' > templates/index_footer.html + printf '' > templates/tag_index_header.html + printf '' > templates/tag_index_footer.html + printf '

$$TITLE

' > 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/&/\&/g' \ + -e 's//\>/g' \ + -e '/^```$$/{s,.*,,;x;p;/^<\/code>/d;s,.*,
,;bT}' \
+		-e 'x;/<\/code>/{x;s,\$$,\$,g;$$G;p;d};x' \
+		-e 's,\\\$$,\$,g' \
+		-e '/^####/{s,^####,

,;s,$$,

,;H;s,.*,,;x;p;d}' \ + -e '/^###/{s,^###,

,;s,$$,

,;H;s,.*,,;x;p;d}' \ + -e '/^##/{s,^##,

,;s,$$,

,;H;s,.*,,;x;p;d}' \ + -e '/^#/{s,^#,

,;s,$$,

,;H;s,.*,,;x;p;d}' \ + -e 's,`\([^`]*\)`,\1,g' \ + -e 's,\*\*\(\([^*<>][^*<>]*\*\?\)*\)\*\*,\1,g' \ + -e 's,\*\([^*<>][^*<>]*\)\*,\1,g' \ + -e 's,!\[\([^]]*\)\](\([^)]*\)),\1,g' \ + -e 's,\[\([^]]*\)\](\([^)]*\)),\1,g' \ + -e '/^- /{s,^- ,
  • ,;s,$$,
  • ,;x;/^<\/ul>/{x;bL};p;s,.*,
      ,;bT}' \ + -e '/^[1-9][0-9]*\. /{s,^[0-9]*\. ,
    • ,;s,$$,
    • ,;x;/^<\/ol>/{x;bL};p;s,.*,
        ,;bT}' \ + -e '/^$$/{x;/^$$/d;p;d}' \ + -e 'x;/^$$/{s,.*,

        ,;bT};x' \ + -e ':L;$$G;p;d' \ + -e ':T;p;:t;s,<\([^/>][^>]*\)>\(\(<[^/>][^>]*>\)*\),\2,;/<[^\/>]/bt;x;/^$$/{$${x;p};d};bL' \ + "$<" | envsubst >> $@; \ + envsubst < templates/article_footer.html >> $@; \ + envsubst < templates/footer.html >> $@; \ + +blog/rss.xml: $(ARTICLES) + printf '\n\n\n%s\n%s\n%s\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 '\n%s\n%s\n%s\n%s\n%s\n\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 '\n\n' >> $@ + +blog/atom.xml: $(ARTICLES) + printf '\n\n%s\n%s\n%s\n\n%s\n\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 '\n%s\n\n%s\n%s\n%s\n%s\n

        %s\n\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 '\n' >> $@ diff --git a/blogit.1 b/blogit.1 new file mode 100644 index 0000000..ebdaaa4 --- /dev/null +++ b/blogit.1 @@ -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. diff --git a/config b/config new file mode 100644 index 0000000..34e1dfe --- /dev/null +++ b/config @@ -0,0 +1 @@ +BLOG_REMOTE:=/var/www/teknolojirehberleri.xyz diff --git a/data/style.css b/data/style.css new file mode 100644 index 0000000..58dbe70 --- /dev/null +++ b/data/style.css @@ -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; + } +} diff --git a/templates/article_entry.html b/templates/article_entry.html new file mode 100644 index 0000000..4c149eb --- /dev/null +++ b/templates/article_entry.html @@ -0,0 +1 @@ +
      1. $TITLE
      2. diff --git a/templates/article_footer.html b/templates/article_footer.html new file mode 100644 index 0000000..b70ebf9 --- /dev/null +++ b/templates/article_footer.html @@ -0,0 +1 @@ +

        Yazının paylaşıldığı tarih: $DATE_POSTED, son düzenleme tarihi: $DATE_EDITED, yazar: $AUTHOR

        diff --git a/templates/article_header.html b/templates/article_header.html new file mode 100644 index 0000000..df11e96 --- /dev/null +++ b/templates/article_header.html @@ -0,0 +1 @@ +

        $TITLE

        \ No newline at end of file diff --git a/templates/article_list_footer.html b/templates/article_list_footer.html new file mode 100644 index 0000000..776b4ca --- /dev/null +++ b/templates/article_list_footer.html @@ -0,0 +1 @@ +
    \ No newline at end of file diff --git a/templates/article_list_header.html b/templates/article_list_header.html new file mode 100644 index 0000000..cf74364 --- /dev/null +++ b/templates/article_list_header.html @@ -0,0 +1 @@ +

    Rehberler

      diff --git a/templates/article_separator.html b/templates/article_separator.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/footer.html b/templates/footer.html new file mode 100644 index 0000000..05401c9 --- /dev/null +++ b/templates/footer.html @@ -0,0 +1,12 @@ +
      +
      + ana sayfa + RSS + atom +
      +

      All site content is in the Public Domain.

      +

      Sitedeki bütün içerikler kamu malıdır.

      +

      Kullanılan teknoloji:blogit

      +

      Esinlenilen website:based cooking

      +
      + diff --git a/templates/header.html b/templates/header.html new file mode 100644 index 0000000..853048a --- /dev/null +++ b/templates/header.html @@ -0,0 +1,16 @@ + + + + + + + + $TITLE + + + diff --git a/templates/index_footer.html b/templates/index_footer.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/index_header.html b/templates/index_header.html new file mode 100644 index 0000000..571b94c --- /dev/null +++ b/templates/index_header.html @@ -0,0 +1,5 @@ + +

      Teknoloji rehberleri. Reklam ve izleyici yok!

      diff --git a/templates/tag_entry.html b/templates/tag_entry.html new file mode 100644 index 0000000..cb23fee --- /dev/null +++ b/templates/tag_entry.html @@ -0,0 +1 @@ +$NAME \ No newline at end of file diff --git a/templates/tag_index_footer.html b/templates/tag_index_footer.html new file mode 100644 index 0000000..e69de29 diff --git a/templates/tag_index_header.html b/templates/tag_index_header.html new file mode 100644 index 0000000..3cd0abd --- /dev/null +++ b/templates/tag_index_header.html @@ -0,0 +1,5 @@ + +

      Etiketle rehber bulun: $TAGS

      diff --git a/templates/tag_list_footer.html b/templates/tag_list_footer.html new file mode 100644 index 0000000..b9fa558 --- /dev/null +++ b/templates/tag_list_footer.html @@ -0,0 +1 @@ +

      \ No newline at end of file diff --git a/templates/tag_list_header.html b/templates/tag_list_header.html new file mode 100644 index 0000000..7a57395 --- /dev/null +++ b/templates/tag_list_header.html @@ -0,0 +1 @@ +

      Tags: \ No newline at end of file diff --git a/templates/tag_separator.html b/templates/tag_separator.html new file mode 100644 index 0000000..c3a6e48 --- /dev/null +++ b/templates/tag_separator.html @@ -0,0 +1 @@ +, \ No newline at end of file