『 Momentous Script 』

Tok Ketua


Note to Visitor(s) : If you want to share any of my post here, head to 'Archive', click on its title then copy from address bar to get the individual post URL.

To-Dos : Happy blogging!
Status : Building healthier relationship w/ digital world.


Home About Archive RSS Feeds Guestbook


Messaging Rectangle

From neocities/nekoweb/nekocafe or have a personal site of your own? Feel free to drop your site for me to check out here too!^^ 


Compass






Credit : Icons by Nightlight-Lullaby and PetraPixel, Blogskin by Wanaseoby from Blogger, Mouse Effect by MF2FM. Custom Blogger Archive by Kher Cheng Guan.




© 2013 - Eternity | Hazirul Shahran. Powered by Batcave and Blogger.com.
Creating Manual XML File for Automated Archive

 Creating XML file by scratch never in my bucket list whatsoever when in comes to coding but somewhere somehow I sway myself to do so for my backup blog. It seems daunting at first but when I got the hang of it, it's fairly alright. A bit tedious to manual update both blog post and XML file then make sure the info is in synch though. Very lucky that I understand Javascript — that I use to load blog archive — enough to make some tweak that work with my format made for Nekoweb's RSS feed and automated archive or I have to go for the old way of internal link... the horrors!

Tips: Search up 'xml javascript for blog archive'. Below is Javascript coding that I tweak for Nekoweb-specific RSS formatting.


// Function to fetch and parse the XML file

async function loadBlogArchive() {

  try {

    const response = await fetch('feed.xml');

    if (!response.ok) {

      throw new Error(`HTTP error! status: ${response.status}`);

    }

    const xmlText = await response.text();

    parseAndDisplayArchive(xmlText);

  } catch (error) {

    console.error('Error fetching blog archive:', error);

    document.getElementById('archive-container').innerHTML = '<p>Could not load archive.</p>';

  }

}


// Function to parse the XML and build the archive display

function parseAndDisplayArchive(xmlString) {

  const parser = new DOMParser();

  const xmlDoc = parser.parseFromString(xmlString, "application/xml");

  const posts = xmlDoc.getElementsByTagName('item');

  const archiveContainer = document.getElementById('archive-container');

  let currentMonthYear = "";


  for (let i = 0; i < posts.length; i++) {

    const post = posts[i];

    const title = post.getElementsByTagName('title')[0].textContent;

    const url = post.getElementsByTagName('link')[0].textContent;

    const dateString = post.getElementsByTagName('pubDate')[0].textContent;

    const date = new Date(dateString);

    const monthYear = date.toLocaleString('default', { month: 'long', year: 'numeric' });


What to change:

feed.xml - Your xml file name, if different from mine.

This not meant to be a tutorial though, simply explaining my coding process. Hope someone will find it useful!

Labels: