Implement atom feed generator
This commit is contained in:
parent
72fbff60ec
commit
e48d16df44
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
static/atom.xml
|
||||||
|
|
98
generate-feed.php
Normal file
98
generate-feed.php
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
#!/usr/bin/env php
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function set_attr($xml, $name, $value) {
|
||||||
|
xmlwriter_start_attribute($xml, $name);
|
||||||
|
xmlwriter_text($xml, $value);
|
||||||
|
xmlwriter_end_attribute($xml);
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_elem($xml, $tag, $content, $attributes = []) {
|
||||||
|
xmlwriter_start_element($xml, $tag);
|
||||||
|
|
||||||
|
foreach ($attributes as $name=>$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(["<body>", "</body>"], "", $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);
|
||||||
|
|
@ -4,17 +4,24 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<title>Reimar's articles</title>
|
<title>Reimar's articles</title>
|
||||||
<link rel="stylesheet" href="assets/style.css">
|
<link rel="stylesheet" href="assets/style.css" />
|
||||||
|
<link rel="alternate" href="atom.xml" type="application/atom+xml" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Reimar's articles</h1>
|
<h1>Reimar's articles</h1>
|
||||||
<p>This is where I publish my writings.</p>
|
<p>This is where I publish my writings.</p>
|
||||||
<br>
|
|
||||||
|
<br />
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<time>2025-08-02</time> — <a href="upgrade-insecure-requests.html">Handling the Upgrade-Insecure-Requests header in nginx</a>
|
<time>2025-08-02</time> — <a href="upgrade-insecure-requests.html">Handling the Upgrade-Insecure-Requests header in nginx</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<a href="atom.xml">Atom feed</a>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
@ -6,10 +6,14 @@
|
|||||||
<meta name="viewport" content="width=device-width" />
|
<meta name="viewport" content="width=device-width" />
|
||||||
<title>Handling the Upgrade-Insecure-Requests header in nginx</title>
|
<title>Handling the Upgrade-Insecure-Requests header in nginx</title>
|
||||||
<link rel="stylesheet" href="assets/style.css" />
|
<link rel="stylesheet" href="assets/style.css" />
|
||||||
|
<link rel="alternate" href="atom.xml" type="application/atom+xml" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Handling the Upgrade-Insecure-Requests header in nginx</h1>
|
<header>
|
||||||
<span class="published">Published on <time datetime="2025-08-02">August 2nd, 2025</time></span>
|
<h1>Handling the Upgrade-Insecure-Requests header in nginx</h1>
|
||||||
|
<span class="published">Published on <time datetime="2025-08-02">August 2nd, 2025</time></span>
|
||||||
|
</header>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Today it is considered a de facto security standard for the
|
Today it is considered a de facto security standard for the
|
||||||
web, that all HTTP requests automatically be redirected to
|
web, that all HTTP requests automatically be redirected to
|
||||||
@ -37,12 +41,12 @@
|
|||||||
|
|
||||||
<fieldset class="table-of-contents">
|
<fieldset class="table-of-contents">
|
||||||
<legend>Table of contents</legend>
|
<legend>Table of contents</legend>
|
||||||
<a href="#configuring">Configuring nginx</a><br>
|
<a href="#configuring">Configuring nginx</a><br />
|
||||||
<a href="#cloudflare">Using Cloudflare</a><br>
|
<a href="#cloudflare">Using Cloudflare</a><br />
|
||||||
<a href="#testing">Testing the configuration</a>
|
<a href="#testing">Testing the configuration</a>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<h2 id="configuring"><a href="#configuring">Configuring nginx</a></h2>
|
<h2 id="configuring">Configuring nginx</h2>
|
||||||
<p>
|
<p>
|
||||||
In its essence, the configuration is very simple: For every
|
In its essence, the configuration is very simple: For every
|
||||||
request, we want to check if the scheme is <code>http</code>
|
request, we want to check if the scheme is <code>http</code>
|
||||||
@ -105,7 +109,7 @@ server {
|
|||||||
}
|
}
|
||||||
}</pre>
|
}</pre>
|
||||||
|
|
||||||
<h2 id="cloudflare"><a href="#cloudflare">Using Cloudflare</a></h2>
|
<h2 id="cloudflare">Using Cloudflare</h2>
|
||||||
<p>
|
<p>
|
||||||
If you are using Cloudflare, you will have to make some
|
If you are using Cloudflare, you will have to make some
|
||||||
changes to this configuration. In this case, all requests
|
changes to this configuration. In this case, all requests
|
||||||
@ -138,7 +142,7 @@ map "$http_cf_visitor+$http_upgrade_insecure_requests" $upgrade {
|
|||||||
completely disabled.
|
completely disabled.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h2 id="testing"><a href="#testing">Testing the configuration</a></h2>
|
<h2 id="testing">Testing the configuration</h2>
|
||||||
<p>
|
<p>
|
||||||
You can use curl to make sure the configuration works
|
You can use curl to make sure the configuration works
|
||||||
properly. The <code>--head</code> option sends a
|
properly. The <code>--head</code> option sends a
|
||||||
@ -160,6 +164,8 @@ curl --head http://example.com --header "Upgrade-Insecure-Requests: 1"</pre>
|
|||||||
sure it also returns 200.
|
sure it also returns 200.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p><a href="index.html">Back</a></p>
|
<footer>
|
||||||
|
<p><a href="index.html">Back</a></p>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user