logo

blog

My website can't be that messy, right? git clone https://hacktivis.me/git/blog.git
commit: f023f587c157540b094e01228fca77d643a423ad
parent 57ec372ad73c6790b57a3d25fa6b25ddfe0dcc09
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed,  8 Mar 2023 23:43:47 +0100

new_article.sh: Move to Atom fragment

Diffstat:

Mnew_article.sh96++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 49 insertions(+), 47 deletions(-)

diff --git a/new_article.sh b/new_article.sh @@ -1,56 +1,58 @@ -#!/bin/sh -v -if [ ${#} -lt 1 ] -then -${ht}echo 'Usage: articles/new.sh Title' -${ht}exit 1 -fi -title="${1}" -title_url="$(echo \"$title\" | jq -r '@uri')" +#!/bin/sh +case $# in +1) + title="${1}" + file="${1}" +;; +2) + title="${2}" + file="${1}" +;; +*) + echo 'Usage: articles/new.sh [filename] <title>' + exit 1 +;; +esac + +file_url="/articles/$(echo \"$file\" | jq -r '@uri')" timestamp="$(date -u +%FT%TZ)" ht=" " WORKDIR="$(dirname $0)" -cat >"${WORKDIR}/articles/${title}.shtml" <<-EOF -<!DOCTYPE html> -<html lang="en"> -${ht}<head> -<!--#include file="/templates/head.shtml" --> -${ht}${ht}<meta property="og:type" content="article"/> -${ht}${ht}<meta property="og:title" content="${title}"/> -${ht}${ht}<title>${title} — Cyber-home of lanodan</title> -${ht}</head> -${ht}<body> -<!--#include file="/templates/en/nav.shtml" --> -<!--#include file="/articles/${title}.xhtml"--> -${ht}${ht}<a href="/articles/${title_url}.xhtml">article only(plain XHTML)</a> -<!--#include file="/templates/en/footer.shtml" --> -${ht}</body> -</html> +if grep -q "/articles/${file}" feed.atom +then + echo 'Error: article already in feed.atom' + exit 1 +else + ed "${WORKDIR}/feed.atom" <<-EOF +/new.sh: new articles here/ +a +<!--#include file="/articles/${file}.xml"--> +. +w +q EOF +fi -cat >"${WORKDIR}/articles/${title}.xhtml" <<-EOF -<article xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="h-entry"> -<a href="/articles/${title_url}"><h1>${title}</h1></a> -<p><a href="">Fediverse post for comments</a>, published on ${timestamp}, last updated on ${timestamp}</p> -</article> -EOF +cat >"${WORKDIR}/articles/${file}.xml" <<-EOF +<entry> +<title>${title}</title> +<link rel="alternate" type="text/html" href="${file_url}"/> +<id>https://hacktivis.me${file_url}</id> +<published>${timestamp}</published> +<updated>${timestamp}</updated> +<!-- +<link rel="external replies" type="application/activity+json" href="https://queer.hacktivis.me/objects/50be9d37-dee6-4c69-818e-013fa3b010d0" /> +<link rel="external replies" type="text/html" href="https://queer.hacktivis.me/objects/50be9d37-dee6-4c69-818e-013fa3b010d0" /> +--> +<content type="xhtml"> +<div xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" class="h-entry"> +<a href="${file_url}"><h1>${title}</h1></a> -#TODO: Grep for the id before appending -grep "<id>https://hacktivis.me/articles/${title_url}</id>" \ -"${WORKDIR}/feed.atom" || ed "${WORKDIR}/feed.atom" <<-EOF -/new.sh: new articles here/ -a -${ht}<entry> -${ht}${ht}<title>${title}</title> -${ht}${ht}<link rel="alternate" type="text/html" href="/articles/${title_url}"/> -${ht}${ht}<id>https://hacktivis.me/articles/${title_url}</id> -${ht}${ht}<published>${timestamp}</published> -${ht}${ht}<updated>${timestamp}</updated> -${ht}${ht}<content type="xhtml"><div xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> -<!--#include file="/articles/${title}.xhtml"--> -${ht}${ht}</div></content> -${ht}</entry> +<!-- Article content goes here --> -. -wq +</div> +</content> +</entry> EOF +