152 lines
3.8 KiB
Makefile
152 lines
3.8 KiB
Makefile
# Static site builder
|
|
#
|
|
# It allows for the creation a diary and a blog.
|
|
# It follows pretty "unixy" way to articulate the build.
|
|
# It uses Pandoc, Python3 and POSIX Commands
|
|
#
|
|
|
|
SRC_DIR := src
|
|
DIARY_DIR := src/diary
|
|
BLOG_DIR := src/blog
|
|
BUILD_DIR := build
|
|
|
|
|
|
# Commands Configuration
|
|
BLOG_ENTRIES_LIST := .entries.csv
|
|
SORT := sort -r
|
|
# Utility Function
|
|
ESCAPE_PATH = $(shell echo $(1) | sed 's/\//\\\//g')
|
|
|
|
# Pandoc basic configuration
|
|
PANDOC := pandoc -s
|
|
PANDOC_FILTERS :=
|
|
|
|
PANDOC_METADATA = \
|
|
--section-divs \
|
|
--template=templates/default.html \
|
|
--metadata-file metadata.yaml \
|
|
--metadata=blog_entries_list:"$(BLOG_ENTRIES_LIST)" \
|
|
--metadata=path="$(shell echo $@ | sed -e 's/build//g' )" \
|
|
--metadata=git_initial_date="$(shell git log --reverse -n 1 --pretty=format:%aI -- $< || echo 'draft')" \
|
|
--metadata=git_date="$(shell git log -n 1 --pretty=format:%aI -- $< || echo 'draft')"
|
|
|
|
PANDOC_COMMAND = $(PANDOC) $(PANDOC_FILTERS) $(PANDOC_METADATA)
|
|
|
|
# Blog Configuration
|
|
COMMENT_SECTION := templates/comment-section.html
|
|
PANDOC_BLOG_FILTER := filters/blog_feed.py
|
|
PANDOC_DIARY_FILTER := filters/diary.py
|
|
|
|
|
|
|
|
# Public Pages configuration
|
|
#
|
|
# All markdown files
|
|
PAGES = \
|
|
build/index.html \
|
|
build/contact.html
|
|
|
|
# Blog Configuration
|
|
BLOG_FEEDS = build/blog/index.html build/blog/rss.xml
|
|
BLOG_ENTRIES = $(shell \
|
|
find $(BLOG_DIR) -mindepth 2 -type f -name '*.md' \
|
|
| sed -e 's/\.md/.html/' \
|
|
| sed -e 's/$(call ESCAPE_PATH,$(BLOG_DIR))/$(call ESCAPE_PATH,$(BUILD_DIR))\/blog/g' \
|
|
| $(SORT) \
|
|
)
|
|
BLOG_BUILD := $(BUILD_DIR)/blog
|
|
ENTRIES_TO_RSS := ./scripts/entries2rss.py
|
|
|
|
# Diary Configuration
|
|
DIARY_ENTRIES = $(shell \
|
|
find $(DIARY_DIR) -type f -name '*.md' \
|
|
| sed -e 's/\.md/.html/' \
|
|
| sed -e 's/$(call ESCAPE_PATH,$(DIARY_DIR))/$(call ESCAPE_PATH,$(BUILD_DIR))\/diary/g' \
|
|
| $(SORT) \
|
|
)
|
|
DIARY_BUILD := $(BUILD_DIR)/diary
|
|
DIARY_COMMAND := ./scripts/diary.py $(DIARY_DIR) $(DIARY_BUILD)
|
|
DIARY_INDEX := $(DIARY_BUILD)/index.html $(shell $(DIARY_COMMAND) index-files)
|
|
|
|
# Build Rules
|
|
|
|
# PHONY Rules
|
|
.PHONY: serve clean info css
|
|
|
|
info:
|
|
@echo "Blog Entries"
|
|
@echo $(BLOG_ENTRIES) | sed -e 's/^/\t/g;s/\ /\n\t/g'
|
|
@echo "Diary Entries"
|
|
@echo $(DIARY_ENTRIES) | sed -e 's/^/\t/g;s/\ /\n\t/g'
|
|
|
|
|
|
all: $(PAGES) $(BLOG_FEEDS) $(DIARY_INDEX) css
|
|
|
|
css:
|
|
mkdir -p $(BUILD_DIR)/css
|
|
cp -f $(SRC_DIR)/css/* $(BUILD_DIR)/css/
|
|
|
|
serve:
|
|
python3 -m http.server --directory $(BUILD_DIR)
|
|
|
|
clean:
|
|
rm -rf $(BUILD_DIR) $(BLOG_ENTRIES_LIST)
|
|
|
|
_diary_command:
|
|
@echo "$(DIARY_COMMAND)"
|
|
|
|
# File Rules
|
|
|
|
# Blog related rules
|
|
|
|
$(BLOG_ENTRIES_LIST): $(BLOG_ENTRIES)
|
|
|
|
$(BUILD_DIR)/blog/%.html: $(BLOG_DIR)/%.md $(COMMENT_SECTION)
|
|
mkdir -p $(shell dirname $@)
|
|
[[ -d "$(shell dirname $<)/assets" ]] \
|
|
&& cp -r $(shell dirname $<)/assets/. $(shell dirname $@)/assets \
|
|
|| echo "Entry with no assets"
|
|
$(PANDOC_COMMAND) \
|
|
--filter $(PANDOC_BLOG_FILTER) \
|
|
--include-after-body=$(COMMENT_SECTION) \
|
|
-i $< -o $@
|
|
|
|
$(BLOG_BUILD)/index.html: $(BLOG_DIR)/index.md $(BLOG_ENTRIES_LIST)
|
|
cat $(BLOG_ENTRIES_LIST) \
|
|
| $(SORT) \
|
|
| $(ENTRIES_TO_RSS) html \
|
|
| $(PANDOC_COMMAND) -i $< -i - -o $@
|
|
|
|
$(BLOG_BUILD)/rss.xml: $(BLOG_ENTRIES_LIST)
|
|
cat $(BLOG_ENTRIES_LIST) \
|
|
| $(SORT) \
|
|
| ./scripts/entries2rss.py \
|
|
> $@
|
|
|
|
# Diary Related rules.
|
|
|
|
$(DIARY_BUILD)/%.html: $(DIARY_DIR)/%.md
|
|
mkdir -p $(shell dirname $@)
|
|
$(PANDOC_COMMAND) \
|
|
--filter $(PANDOC_DIARY_FILTER) \
|
|
--metadata=diary_dir:$(DIARY_DIR) \
|
|
-i $< -o $@
|
|
|
|
$(DIARY_BUILD)/%.html: $(DIARY_DIR)/%-*.md
|
|
mkdir -p $(shell dirname $@)
|
|
$(PANDOC_COMMAND) \
|
|
--metadata=diary_dir:$(DIARY_DIR) \
|
|
-i $< -o $@
|
|
|
|
$(DIARY_BUILD)/index.html: $(DIARY_ENTRIES)
|
|
mkdir -p $(shell dirname $@)
|
|
$(DIARY_COMMAND) index-full \
|
|
| $(PANDOC_COMMAND) -i - -o $@
|
|
|
|
# Regular page related rules.
|
|
|
|
$(BUILD_DIR)/%.html: $(SRC_DIR)/%.md
|
|
mkdir -p $(shell dirname $@)
|
|
$(PANDOC_COMMAND) -i $< -o $@
|
|
|