Skip to content

Commit

Permalink
add rss feed
Browse files Browse the repository at this point in the history
  • Loading branch information
ngalaiko committed Jun 17, 2024
1 parent 78a585e commit fb102ce
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ OUTPUT_OTHER_FILES := $(patsubst $(SRC_DIR)/%,$(BUILD_DIR)/%,$(INPUT_OTHER_FILES
# Combine all outputs
OUTPUT := $(OUTPUT_MD_FILES) $(OUTPUT_COCKTAIL_FILES) $(BUILD_DIR)/cocktails/index.html $(OUTPUT_COCKTAIL_IMAGE_FILES)
OUTPUT += $(BUILD_DIR)/records/index.html $(BUILD_DIR)/movies/index.html $(OUTPUT_MOVIE_IMAGE_FILES)
OUTPUT += $(OUTPUT_RECORD_IMAGE_FILES) $(BUILD_DIR)/posts/index.html $(BUILD_DIR)/posts/index.atom $(OUTPUT_IMAGE_FILES)
OUTPUT += $(BUILD_DIR)/places/index.html $(OUTPUT_OTHER_FILES)
OUTPUT += $(OUTPUT_RECORD_IMAGE_FILES) $(BUILD_DIR)/posts/index.html $(BUILD_DIR)/posts/index.atom $(BUILD_DIR)/posts/index.xml
OUTPUT += $(OUTPUT_IMAGE_FILES) $(BUILD_DIR)/places/index.html $(OUTPUT_OTHER_FILES)

# Macros
templ = templates/_layout.html.jinja j2_customize.py templates/$1
Expand Down Expand Up @@ -115,6 +115,11 @@ $(BUILD_DIR)/posts/index.html: $(INPUT_POST_FILES) $(call templ,posts/index.html
@mkdir -p "$(dir $@)"
@ls $(INPUT_POST_FILES) | xargs -I {} sh -c './scripts/convert_md.sh {} | $(YQ_BIN) --output-format json' | $(JQ_BIN) --slurp '{ posts: . }' | $(J2_BIN) -f json posts/index.html.jinja -o="$@" || exit 1

$(BUILD_DIR)/posts/index.xml: $(INPUT_POST_FILES) $(call templ,posts/index.xml.jinja)
@echo '$(SRC_DIR)/posts/*.md -> $@'
@mkdir -p "$(dir $@)"
@ls $(INPUT_POST_FILES) | xargs -I {} sh -c './scripts/convert_md.sh {} | $(YQ_BIN) --output-format json' | $(JQ_BIN) --slurp '{ posts: . }' | $(J2_BIN) -f json posts/index.xml.jinja -o="$@" || exit 1

$(BUILD_DIR)/posts/index.atom: $(INPUT_POST_FILES) $(call templ,posts/index.atom.jinja)
@echo '$(SRC_DIR)/posts/*.md -> $@'
@mkdir -p "$(dir $@)"
Expand Down
1 change: 1 addition & 0 deletions templates/posts/index.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

{% block head %}
<link rel="alternate" type="application/atom+xml" href="/posts/index.atom">
<link rel="alternate" type="application/rss+xml" href="/posts/index.xml">
{% endblock %}

{% block content %}
Expand Down
30 changes: 30 additions & 0 deletions templates/posts/index.xml.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>posts by nikita galaiko</title>
<link>https://nikita.galaiko.rocks/posts</link>
<description>This is an RSS feed of posts by Nikita Galaiko</description>
{%- set latest = posts | sort(attribute="date",reverse=True) | first -%}
<lastBuildDate>{{ latest.date }}T00:00:00Z</lastBuildDate>
<managingEditor>[email protected] (Nikita Galaiko)</managingEditor>
<webMaster>[email protected] (Nikita Galaiko)</webMaster>
<ttl>60</ttl>
<image>
<url>https://nikita.galaiko.rocks/favicon.ico</url>
<title>posts by nikita galaiko</title>
<link>https://nikita.galaiko.rocks/posts</link>
</image>
{%- for post in posts | sort(attribute="date", reverse = True) %}
<item>
<title>{{ post.title }}</title>
{%- set path = "/posts/" + post.path|replace('.md', '.html') %}
{%- set guid = post.id if 'id' in post else path %}
<link>https://nikita.galaiko.rocks{{ path }}</link>
<guid>https://nikita.galaiko.rocks{{ guid }}</guid>
<pubDate>{{ post.date }}T00:00:00Z</pubDate>
<description><![CDATA[{{ post.content }}]]></description>
</item>
{%- endfor %}
</channel>
</rss>

0 comments on commit fb102ce

Please sign in to comment.