From e48d16df4414bba1362fa1551a79baaa77cdcf28 Mon Sep 17 00:00:00 2001 From: Reimar Date: Sun, 3 Aug 2025 17:24:16 +0200 Subject: [PATCH] Implement atom feed generator --- .gitignore | 2 + generate-feed.php | 98 +++++++++++++++++++++++++++ static/index.html | 11 ++- static/upgrade-insecure-requests.html | 22 +++--- 4 files changed, 123 insertions(+), 10 deletions(-) create mode 100644 .gitignore create mode 100644 generate-feed.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68368f2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +static/atom.xml + diff --git a/generate-feed.php b/generate-feed.php new file mode 100644 index 0000000..35ffb84 --- /dev/null +++ b/generate-feed.php @@ -0,0 +1,98 @@ +#!/usr/bin/env php +$value) { + set_attr($xml, $name, $value); + } + + if ($content) xmlwriter_text($xml, $content); + + xmlwriter_end_element($xml); +} + +$xml = xmlwriter_open_uri(__DIR__ . "/static/atom.xml"); +xmlwriter_set_indent($xml, true); +xmlwriter_set_indent_string($xml, "\t"); +xmlwriter_start_document($xml, "1.0", "utf-8"); + +xmlwriter_start_element($xml, "feed"); +set_attr($xml, "xmlns", "http://www.w3.org/2005/Atom"); + +add_elem($xml, "title", "Reimar's articles"); +add_elem($xml, "id", "https://reim.ar/"); + +xmlwriter_start_element($xml, "author"); +add_elem($xml, "name", "Reimar"); +add_elem($xml, "email", "mail@reim.ar"); +add_elem($xml, "uri", "https://reim.ar"); +xmlwriter_end_element($xml); + +add_elem($xml, "link", null, ["href" => "https://articles.reim.ar"]); +add_elem($xml, "link", null, ["rel" => "self", "href" => "https://articles.reim.ar/atom.xml"]); + +$updated = 0; +$entries = []; + +foreach (scandir(__DIR__ . "/static") as $file) { + $path = __DIR__ . "/static/" . $file; + + if (is_dir($path) || !str_ends_with($path, ".html")) continue; + + $doc = new DOMDocument(); + $doc->load($path); + + $xpath = new DOMXPath($doc); + + $author = $xpath->query("//meta[@name='author']"); + if (!count($author)) continue; + + $published = $xpath->query("//*[@class='published']/time")[0]->attributes["datetime"]->value; + $published = date("c", strtotime($published)); + $updated = max($updated, strtotime($published)); + + $title = $doc->getElementsByTagName("title")[0]->textContent; + + $doc->getElementsByTagName("header")[0]->remove(); + $doc->getElementsByTagName("footer")[0]->remove(); + + $content = $doc->saveXML($doc->getElementsByTagName("body")[0]); + $content = str_replace(["", ""], "", $content); + + $entries[] = [ + "file" => $file, + "title" => $title, + "published" => $published, + "content" => $content, + ]; + +} + +add_elem($xml, "updated", date("c", $updated)); + +foreach ($entries as $entry) { + xmlwriter_start_element($xml, "entry"); + add_elem($xml, "id", "https://articles.reim.ar/" . $entry["file"]); + add_elem($xml, "link", null, [ + "rel" => "alternate", + "href" => "https://articles.reim.ar/" . $entry["file"], + "type" => "text/html", + ]); + add_elem($xml, "title", $entry["title"]); + add_elem($xml, "published", $entry["published"]); + add_elem($xml, "updated", $entry["published"]); + add_elem($xml, "content", $entry["content"], ["type" => "html"]); + xmlwriter_end_element($xml); +} + +xmlwriter_end_document($xml); +xmlwriter_flush($xml); + diff --git a/static/index.html b/static/index.html index 01581b2..bdface3 100644 --- a/static/index.html +++ b/static/index.html @@ -4,17 +4,24 @@ Reimar's articles - + +

Reimar's articles

This is where I publish my writings.

-
+ +
+ + +
+ + Atom feed diff --git a/static/upgrade-insecure-requests.html b/static/upgrade-insecure-requests.html index af53928..74e7602 100644 --- a/static/upgrade-insecure-requests.html +++ b/static/upgrade-insecure-requests.html @@ -6,10 +6,14 @@ Handling the Upgrade-Insecure-Requests header in nginx + -

Handling the Upgrade-Insecure-Requests header in nginx

- Published on +
+

Handling the Upgrade-Insecure-Requests header in nginx

+ Published on +
+

Today it is considered a de facto security standard for the web, that all HTTP requests automatically be redirected to @@ -37,12 +41,12 @@

Table of contents - Configuring nginx
- Using Cloudflare
+ Configuring nginx
+ Using Cloudflare
Testing the configuration
-

Configuring nginx

+

Configuring nginx

In its essence, the configuration is very simple: For every request, we want to check if the scheme is http @@ -105,7 +109,7 @@ server { } } -

Using Cloudflare

+

Using Cloudflare

If you are using Cloudflare, you will have to make some changes to this configuration. In this case, all requests @@ -138,7 +142,7 @@ map "$http_cf_visitor+$http_upgrade_insecure_requests" $upgrade { completely disabled.

-

Testing the configuration

+

Testing the configuration

You can use curl to make sure the configuration works properly. The --head option sends a @@ -160,6 +164,8 @@ curl --head http://example.com --header "Upgrade-Insecure-Requests: 1" sure it also returns 200.

-

Back

+