Skip to content

Commit

Permalink
improve Makefile and pandoc configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
pavel-demin committed Nov 17, 2024
1 parent 902b218 commit 768ed60
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ BASE_PATH =

SITE = _site

PAGES = $(filter-out index, $(basename $(notdir $(wildcard md/*.md))))
CONTENT = $(addprefix $(SITE)/, etc css img index.html $(addsuffix /index.html, $(PAGES)))
FILES = $(shell find md -type f -name \*.md)
PAGES = $(patsubst %.md, %/index.html, $(patsubst %/index.md, %/index.html, $(FILES)))
CONTENT = $(addprefix $(SITE)/, css etc img) $(patsubst md/%, $(SITE)/%, $(PAGES))

PANDOC = pandoc -d defaults.yml -M base_url=$(BASE_URL) -M base_path=$(BASE_PATH)

Expand All @@ -15,14 +16,14 @@ RM = rm -rf
all: $(CONTENT)

$(SITE)/%: %
@echo ">> Copying $^"
@echo ">> Copying $<"
@$(MKDIR) $(@D)
@$(CP) $^ $@
@$(CP) $< $(@D)

$(SITE)/%.html $(SITE)/%/index.html: md/%.md
@echo ">> Converting $^"
@echo ">> Converting $<"
@$(MKDIR) $(@D)
@$(PANDOC) -M page=$* -o $@ $^
@$(PANDOC) -M page=$* -o $@ $<

serve:
@python3 -m http.server --bind 127.0.0.1 --directory $(SITE)
Expand Down
2 changes: 1 addition & 1 deletion defaults.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
standalone: true
template: page.html

reader: markdown-implicit_figures
reader: commonmark+gfm_auto_identifiers+pipe_tables
writer: html

highlight-style: null
Expand Down
12 changes: 6 additions & 6 deletions filters.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ end

function change_meta(m)
meta = m
if m.page == "index" then
m.canonical = stringify(m.base_url) .. "/"
else
m.canonical = stringify(m.base_url) .. "/" .. m.page .. "/"
p = m.page:gsub("/?index$", "")
if p ~= "" then
p = p .. "/"
end
m.canonical = stringify(m.base_url) .. "/" .. p
m.title = title or m.site_title
return m
end

function expand(s)
v = meta[s:sub(2, -2)]
v = meta[s]
if v then
return stringify(v)
end
end

function change_link_target(l)
l.target = l.target:gsub("(%b$$)", expand)
l.target = l.target:gsub("%$(.-)%$", expand)
if l.target:sub(1, 1) == "/" then
l.target = meta.base_path .. l.target
end
Expand Down

0 comments on commit 768ed60

Please sign in to comment.