-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
16 changed files
with
170 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters