Skip to content

Commit

Permalink
RSS feed
Browse files Browse the repository at this point in the history
Someone e-mailed me asking for an RSS feed.
I was bored, sick and had nothing to do and
felt like it would be good exercise.
Made javascript/rss.js to go over every .html
file in posts folder and take certain information
from each post to make a RSS item. I just have
to remember to run the script before pushing to
Github from now on. Added RSS button to footer.
  • Loading branch information
NecRaul committed Dec 20, 2024
1 parent fed153e commit e59edc0
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 3x3.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ <h2>Manga</h2>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand All @@ -105,4 +106,3 @@ <h2>Manga</h2>
</div>
</body>
</html>

2 changes: 1 addition & 1 deletion 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ <h3 id="redirect">You are being redirected in 5...</h3>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand All @@ -45,4 +46,3 @@ <h3 id="redirect">You are being redirected in 5...</h3>
<script type="text/javascript" src="/javascript/redirect.js"></script>
</body>
</html>

1 change: 1 addition & 0 deletions about.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ <h2>About Me</h2>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand Down
59 changes: 59 additions & 0 deletions feed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>NecRaul's website</title>
<link>https://www.kuroneko.dev/</link>
<description>Documenting the voices in my head</description>
<language>en-us</language>
<atom:link href="https://www.kuroneko.dev/feed.xml" rel="self" type="application/rss+xml"/>

<item>
<title>Accord's Library or: How I Learned to Stop Worrying and Hate SQEX</title>
<link>https://www.kuroneko.dev/posts/Accords_Library_or_How_I_Learned_to_Stop_Worrying_and_Hate_SQEX.html</link>
<pubDate>Sun, 01 Dec 2024 00:00:00 GMT</pubDate>
<description>I think Square Enix SUCKS</description>
</item>

<item>
<title>I just want to be left alone</title>
<link>https://www.kuroneko.dev/posts/I_just_want_to_be_left_alone.html</link>
<pubDate>Thu, 13 Jun 2024 00:00:00 GMT</pubDate>
<description>Uncle Ted, my beloved</description>
</item>

<item>
<title>Kyoto Animation and atrophy</title>
<link>https://www.kuroneko.dev/posts/Kyoto_Animation_and_atrophy.html</link>
<pubDate>Wed, 05 Jun 2024 00:00:00 GMT</pubDate>
<description>KyoAni has fallen. Billions must rewatch Haruhi.</description>
</item>

<item>
<title>Note-takingfags are obnoxious</title>
<link>https://www.kuroneko.dev/posts/Note-takingfags_are_obnoxious.html</link>
<pubDate>Mon, 26 Feb 2024 00:00:00 GMT</pubDate>
<description>Obsidian as a second brain? You don't even have a brain!</description>
</item>

<item>
<title>The Sekimeiya: Spun Glass Review</title>
<link>https://www.kuroneko.dev/posts/The_Sekimeiya_Spun_Glass_Review.html</link>
<pubDate>Thu, 15 Feb 2024 00:00:00 GMT</pubDate>
<description>No H scenes included</description>
</item>

<item>
<title>Haruhi Suzumiya and where it's all headed</title>
<link>https://www.kuroneko.dev/posts/Haruhi_Suzumiya_and_where_its_all_headed.html</link>
<pubDate>Sun, 28 Jan 2024 00:00:00 GMT</pubDate>
<description>Our Lord and Savior</description>
</item>

<item>
<title>Tachiyomi and The Importance of Gatekeeping</title>
<link>https://www.kuroneko.dev/posts/Tachiyomi_and_The_Importance_of_Gatekeeping.html</link>
<pubDate>Tue, 16 Jan 2024 00:00:00 GMT</pubDate>
<description>Another one bites the dust</description>
</item>
</channel>
</rss>
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ <h2>Recent Ramblings</h2>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand All @@ -46,4 +47,3 @@ <h2>Recent Ramblings</h2>
<script type="text/javascript" src="/javascript/index.js"></script>
</body>
</html>

97 changes: 97 additions & 0 deletions javascript/rss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
const fs = require("fs");
const path = require("path");

const postsPath = path.join(__dirname, "../posts");
const feedPath = path.join(__dirname, "../feed.xml");

const postsArray = [];

function parseDate(dateStr) {
const [month, day, year] = dateStr.match(/(\w+) (\d{1,2}), (\d{4})/).slice(1);
const date = new Date(`${month} ${day}, ${year}`);
if (isNaN(date)) {
return null;
}
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(
2,
"0",
)}-${String(date.getDate()).padStart(2, "0")}`;
}

function generateRSS(postsArray) {
const rssItems = postsArray
.map((post) => {
return `
<item>
<title>${post.title}</title>
<link>https://www.kuroneko.dev/posts/${post.post}</link>
<pubDate>${new Date(post.date).toUTCString()}</pubDate>
<description>${post.description}</description>
</item>`;
})
.join("\n");

return `<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>NecRaul's website</title>
<link>https://www.kuroneko.dev/</link>
<description>Documenting the voices in my head</description>
<language>en-us</language>
<atom:link href="https://www.kuroneko.dev/feed.xml" rel="self" type="application/rss+xml"/>
${rssItems}
</channel>
</rss>`;
}

fs.readdir(postsPath, (err, posts) => {
if (err) {
console.error("Error reading folder:", err);
return;
}

posts
.filter((post) => post.endsWith(".html"))
.forEach((post) => {
const postPath = path.join(postsPath, post);

fs.readFile(postPath, "utf8", (err, data) => {
if (err) {
console.error("Error reading post:", post, err);
return;
}

const titleMatch = data.match(/<title>\s*([\s\S]*?)\s*<\/title>/i);
const descriptionMatch = data.match(/<h2>(.*?)<\/h2>/i);
const dateMatch = data.match(/id=["']date["'][^>]*>(.*?)<\/[^>]+>/i);

const title = titleMatch ? titleMatch[1] : "No title found";
const description = descriptionMatch
? descriptionMatch[1]
: "No description found";
const rawDate = dateMatch ? dateMatch[1] : "No date found";
const parsedDate = parseDate(rawDate) || "Invalid date";

postsArray.push({ post, title, description, date: parsedDate });

if (
postsArray.length ===
posts.filter((post) => post.endsWith(".html")).length
) {
postsArray.sort((a, b) =>
a.date > b.date ? -1 : a.date < b.date ? 1 : 0,
);

const rssFeed = generateRSS(postsArray);

fs.writeFile(feedPath, rssFeed, "utf8", (err) => {
if (err) {
console.error("Error writing RSS feed:", err);
} else {
console.log("RSS feed generated successfully at:", feedPath);
}
});
}
});
});
});
2 changes: 1 addition & 1 deletion kuroneko.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ <h2>Kuroneko</h2>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand All @@ -46,4 +47,3 @@ <h2>Kuroneko</h2>
<script type="text/javascript" src="/javascript/kuroneko.js"></script>
</body>
</html>

2 changes: 1 addition & 1 deletion posts.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ <h2>All Ramblings (Newest to Oldest)</h2>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand All @@ -46,4 +47,3 @@ <h2>All Ramblings (Newest to Oldest)</h2>
<script type="text/javascript" src="/javascript/index.js"></script>
</body>
</html>

Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ <h3>Closing notes</h3>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand Down
1 change: 1 addition & 0 deletions posts/Haruhi_Suzumiya_and_where_its_all_headed.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ <h3>Onto the point</h3>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand Down
1 change: 1 addition & 0 deletions posts/I_just_want_to_be_left_alone.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ <h3>Closing notes</h3>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand Down
1 change: 1 addition & 0 deletions posts/Kyoto_Animation_and_atrophy.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ <h3>Closing notes</h3>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand Down
2 changes: 1 addition & 1 deletion posts/Note-takingfags_are_obnoxious.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ <h3>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand All @@ -131,4 +132,3 @@ <h3>
</div>
</body>
</html>

2 changes: 1 addition & 1 deletion posts/Tachiyomi_and_The_Importance_of_Gatekeeping.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ <h3>Gatekeeping</h3>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand All @@ -133,4 +134,3 @@ <h3>Gatekeeping</h3>
</div>
</body>
</html>

2 changes: 1 addition & 1 deletion posts/The_Sekimeiya_Spun_Glass_Review.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ <h3>Conclusion</h3>
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand All @@ -129,4 +130,3 @@ <h3>Conclusion</h3>
</div>
</body>
</html>

1 change: 1 addition & 0 deletions template/post.html.template
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<a class="navitem" href="https://github.com/NecRaul" target="_blank"
>Github</a
>
<a class="navitem" href="/feed.xml" target="_blank">RSS</a>
<a
class="navitem"
href="https://github.com/NecRaul/kuroneko-dev"
Expand Down

0 comments on commit e59edc0

Please sign in to comment.