Compare commits
4 Commits
9e9c0c3e7f
...
397e04e67c
Author | SHA1 | Date | |
---|---|---|---|
397e04e67c | |||
34eb3f0eae | |||
eced0015f4 | |||
320434e9c7 |
2
blog
2
blog
@ -1 +1 @@
|
||||
Subproject commit 865a2f7ca90d28bec65f591dc54ee30e2ef24bc7
|
||||
Subproject commit 555c2e767a4fdb9d9e2ea343ddae61979b72ac67
|
65
makefile
65
makefile
@ -10,46 +10,36 @@ OUT_DIR = site
|
||||
|
||||
ROOT_DIR = $(SRC_DIR)/root
|
||||
|
||||
BLOG_SRC_DIR = blog/blogs
|
||||
BLOG_BASE_DIR = blog/
|
||||
BLOG_BUILD_DIR = $(BLOG_BASE_DIR)out/html/
|
||||
BLOG_OUT_DIR = $(OUT_DIR)/blog
|
||||
BLOG_TMP_DIR = .blogtmp
|
||||
BLOG_INDEX = $(BLOG_BUILD_DIR)/index.html
|
||||
|
||||
PAGES = $(shell find $(ROOT_DIR) -wholename "$(ROOT_DIR)*.html")
|
||||
STYLES = $(shell find $(ROOT_DIR) -wholename "$(ROOT_DIR)*.css")
|
||||
BLOG_PAGES = $(shell find $(BLOG_SRC_DIR) -wholename "$(BLOG_SRC_DIR)*.md")
|
||||
BLOG_IMAGES = $(shell find $(BLOG_SRC_DIR) -wholename "$(BLOG_SRC_DIR)*.png" -o -wholename "$(BLOG_SRC_DIR)*.jpg")
|
||||
|
||||
IMAGES = $(shell find $(IMG_DIR) -wholename "$(IMG_DIR)/*.png")
|
||||
|
||||
HTML_INCLUDES = $(shell find $(SRC_DIR)/inc_html -name *.html)
|
||||
CSS_INCLUDES = $(shell find $(SRC_DIR)/inc_css -name *.css)
|
||||
|
||||
BLOG_INDEX = $(OUT_DIR)/blog.html
|
||||
BLOG_RSS = $(BLOG_OUT_DIR)/index.xml
|
||||
BLOG_INDEX_LINKS = $(BLOG_TMP_DIR)/blogindexlinks.html
|
||||
BLOG_TARGETS = $(BLOG_PAGES:$(BLOG_SRC_DIR)/%.md=$(BLOG_OUT_DIR)/%.html)
|
||||
BLOG_PNG_TARGETS = $(BLOG_IMAGES:$(BLOG_SRC_DIR)/%.png=$(BLOG_OUT_DIR)/%.png)
|
||||
BLOG_JPG_TARGETS = $(BLOG_IMAGES:$(BLOG_SRC_DIR)/%.jpg=$(BLOG_OUT_DIR)/%.jpg)
|
||||
|
||||
HTML_TARGETS = $(PAGES:$(ROOT_DIR)/%.html=$(OUT_DIR)/%.html)
|
||||
CSS_TARGETS = $(STYLES:$(ROOT_DIR)/%.css=$(OUT_DIR)/%.css)
|
||||
PNG_TARGETS = $(IMG_DIR)/%.png=$(OUT_DIR)/%.png
|
||||
|
||||
|
||||
all: html blog | $(OUT_DIR)
|
||||
|
||||
html: $(HTML_TARGETS) $(CSS_TARGETS) | $(OUT_DIR)
|
||||
cp $(IMG_DIR)/*.png $(OUT_DIR)/
|
||||
cp $(IMG_DIR)/*.jpg $(OUT_DIR)/
|
||||
|
||||
deploy: site
|
||||
deploy:
|
||||
cp -r $(OUT_DIR) $(SITE_NAME)
|
||||
rsync -rP $(SITE_NAME) $(HOST):~
|
||||
rm -r $(SITE_NAME)
|
||||
ssh $(HOST) "sudo $(REMOTE_SCRIPT)"
|
||||
|
||||
$(OUT_DIR)/%.html: $(ROOT_DIR)/%.html $(HTML_INCLUDES) $(BLOG_INDEX_LINKS) | $(OUT_DIR)
|
||||
python ppp/ppp.py $< $(HTML_INCLUDES) $(BLOG_INDEX_LINKS) > $@
|
||||
$(OUT_DIR)/%.html: $(ROOT_DIR)/%.html $(HTML_INCLUDES) $(BLOG_INDEX) | $(OUT_DIR)
|
||||
python ppp/ppp.py $< $(HTML_INCLUDES) $(BLOG_INDEX) > $@
|
||||
|
||||
$(OUT_DIR)/%.css: $(ROOT_DIR)/%.css $(CSS_INCLUDES) | $(OUT_DIR)
|
||||
python ppp/ppp.py $< $(CSS_INCLUDES) > $@
|
||||
@ -57,35 +47,22 @@ $(OUT_DIR)/%.css: $(ROOT_DIR)/%.css $(CSS_INCLUDES) | $(OUT_DIR)
|
||||
$(OUT_DIR):
|
||||
mkdir -p $@
|
||||
|
||||
$(BLOG_OUT_DIR)/%.png: $(BLOG_SRC_DIR)/%.png
|
||||
cp $< $@
|
||||
$(BLOG_INDEX):
|
||||
mkdir -p $(BLOG_OUT_DIR)
|
||||
make --directory $(BLOG_BASE_DIR) html
|
||||
|
||||
$(BLOG_OUT_DIR)/%.jpg: $(BLOG_SRC_DIR)/%.jpg
|
||||
cp $< $@
|
||||
|
||||
blog: $(BLOG_TARGETS) $(BLOG_PNG_TARGETS) $(BLOG_JPG_TARGETS) $(BLOG_RSS) | $(BLOG_TMP_DIR)
|
||||
|
||||
$(BLOG_RSS): $(BLOG_PAGES)
|
||||
pipenv run python scripts/mkblogrss.py $(BLOG_PAGES) > $@
|
||||
|
||||
$(BLOG_INDEX_LINKS): $(BLOG_TARGETS) | $(BLOG_TMP_DIR)
|
||||
pipenv run python scripts/mkblogindex.py $(BLOG_TARGETS) > $@
|
||||
|
||||
$(BLOG_OUT_DIR)/%.html: $(BLOG_OUT_DIR)/%.html.tmp $(HTML_INCLUDES) $(CSS_TARGETS)
|
||||
python ppp/ppp.py $< $(HTML_INCLUDES) > $@
|
||||
cp $(CSS_TARGETS) `dirname $@`
|
||||
rm $<
|
||||
|
||||
$(BLOG_OUT_DIR)/%.html.tmp: $(BLOG_SRC_DIR)/%.md | $(BLOG_TMP_DIR)
|
||||
pipenv run python scripts/mkblog.py $< $@
|
||||
|
||||
$(BLOG_OUT_DIR): | $(OUT_DIR)
|
||||
mkdir -p $@
|
||||
|
||||
$(BLOG_TMP_DIR):
|
||||
mkdir -p $@
|
||||
# make blog from submodule and apply site templating
|
||||
blog: $(HTML_INCLUDES) $(CSS_TARGETS)
|
||||
mkdir -p $(BLOG_OUT_DIR)
|
||||
make --directory $(BLOG_BASE_DIR) html
|
||||
cp -r $(BLOG_BUILD_DIR)/* $(BLOG_OUT_DIR)
|
||||
for page in `find "$(BLOG_OUT_DIR)" -wholename "*.html"`; do \
|
||||
pipenv run python ppp/ppp.py $$page $(HTML_INCLUDES) > temp ; \
|
||||
mv temp $$page ; \
|
||||
cp $(CSS_TARGETS) `dirname $$page` ; \
|
||||
done
|
||||
|
||||
clean:
|
||||
rm -rf $(OUT_DIR) $(BLOG_TMP_DIR)
|
||||
rm -rf $(OUT_DIR)
|
||||
|
||||
.PHONY: site
|
||||
.PHONY: blog
|
||||
|
@ -1,59 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import re
|
||||
|
||||
# we expect the arguments to be filepaths to each blog post
|
||||
|
||||
def print_usage():
|
||||
print("\nusage: python mkblogindex.py POSTS\n")
|
||||
print("\n")
|
||||
print("\t\tPOSTS\tfilepaths of blog posts")
|
||||
|
||||
# check args for at least one file path
|
||||
if len(sys.argv) < 2:
|
||||
print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
# posts are arguments from index 1 onwards
|
||||
posts = sys.argv[1:]
|
||||
|
||||
dir_pattern = re.compile("(.+)/(blog\/.+\.html)")
|
||||
path_pattern = re.compile("(.+)\/(\d{4})\/(\d{1,2})\/(\d{1,2})\/(.+).html")
|
||||
title_pattern = re.compile("<h1>(.+)</h1>")
|
||||
|
||||
# filter posts to just those with a date in them
|
||||
posts = [p for p in posts if path_pattern.match(p)]
|
||||
posts.reverse()
|
||||
|
||||
links = []
|
||||
|
||||
# for each file we want to output an <a> tag with a relative href to the site root
|
||||
for path in posts:
|
||||
m = re.match(path_pattern, path)
|
||||
year = m.group(2)
|
||||
month = m.group(3).rjust(2, '0')
|
||||
day = m.group(4).rjust(2, '0')
|
||||
|
||||
date = f'<span class="post-date">{year}-{month}-{day}</span>'
|
||||
|
||||
title = ""
|
||||
with open(path) as f:
|
||||
for line in f:
|
||||
if title_pattern.match(line):
|
||||
title = re.sub(title_pattern, r'<span class="post-title">\1</span>', line).strip()
|
||||
break
|
||||
|
||||
# clean leading directories to get the relative path we'll use for the link
|
||||
url = re.sub(dir_pattern, r"\2", path)
|
||||
|
||||
item = (date, f'<li><a href="{url}">{date}{title}</a></li>')
|
||||
links.append(item)
|
||||
|
||||
# make sure we're properly ordered in reverse date order lol
|
||||
links = sorted(links, key=lambda x: x[0])
|
||||
links.reverse()
|
||||
|
||||
for l in links:
|
||||
print(l[1])
|
||||
|
@ -1,76 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import markdown
|
||||
import pathlib
|
||||
import sys
|
||||
import re
|
||||
|
||||
def print_usage():
|
||||
print("\nusage: python mkblogrss.py POSTS\n")
|
||||
print("\n")
|
||||
print("\t\tPOSTS\tfilepaths of blog posts")
|
||||
|
||||
# check args for at least one file path
|
||||
if len(sys.argv) < 2:
|
||||
print_usage()
|
||||
sys.exit(1)
|
||||
|
||||
# posts are arguments from index 1 onwards
|
||||
posts = sys.argv[1:]
|
||||
|
||||
# header and footer to enclose feed items
|
||||
header = """<?xml version="1.0" encoding="utf-8" ?>
|
||||
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
|
||||
<channel>
|
||||
<title>ktyl.dev</title>
|
||||
<link>https://ktyl.dev/blog/index.html</link>
|
||||
<description>mostly computer stuff!</description>
|
||||
<atom:link href="https://ktyl.dev/blog/index.xml" rel="self" type="application/rss+xml"/>
|
||||
"""
|
||||
footer = "</channel></rss>"
|
||||
|
||||
# regex patterns
|
||||
title_pattern = re.compile("<h1>(.+)</h1>")
|
||||
path_pattern = re.compile("(.+)\/(\d{4})\/(\d{1,2})\/(\d{1,2})\/(.+).md")
|
||||
|
||||
def make_item(path):
|
||||
str = "<item>\n"
|
||||
|
||||
# get the HTML version of the file
|
||||
text = ""
|
||||
with open(path) as f:
|
||||
text = f.read()
|
||||
html = markdown.markdown(text, extensions=["fenced_code"])
|
||||
|
||||
# title
|
||||
title = ""
|
||||
m = title_pattern.match(html)
|
||||
title = m.group(1)
|
||||
str += f"<title>{title}</title>\n"
|
||||
|
||||
# link
|
||||
url = "/".join(pathlib.Path(path).parts[2:])
|
||||
url = url.replace(".md", ".html")
|
||||
link = f"https://ktyl.dev/blog/{url}"
|
||||
str += f"<link>{link}</link>\n"
|
||||
|
||||
# content
|
||||
description = html
|
||||
description = re.sub('<', '<', description)
|
||||
description = re.sub('>', '>', description)
|
||||
str += f"<description>{description}</description>\n"
|
||||
|
||||
# pub date
|
||||
date = re.sub(path_pattern, r'\2-\3-\4', path)
|
||||
str += f"<pubDate>{date}</pubDate>\n"
|
||||
|
||||
str += "</item>"
|
||||
|
||||
return str
|
||||
|
||||
# print everything!
|
||||
print(header)
|
||||
for p in posts:
|
||||
print(make_item(p))
|
||||
print(footer)
|
||||
|
@ -21,7 +21,7 @@
|
||||
<div class="text-panel">
|
||||
|
||||
<ul class="blog-index">
|
||||
#include blogindexlinks.html
|
||||
#include index.html
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user