'use strict';

const convert = require('xml-js');
const axios = require('axios');

const changefreq = {
  yearly: 'yearly',
  monthly: 'monthly',
};

const options = {
  compact: true,
  spaces: 2,
  indentText: true,
};

const sitemap = {
  _declaration: {
    _attributes: {
      version: '1.0',
      encoding: 'utf-8',
    },
  },
  urlset: {
    _attributes: {
      xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9',
    },
    url: [
    ],
  },
};

const getUrl = path => {
  return `https://hiroto-k.github.io${path}`;
};
const getLastModified = async url => {
  const response = await axios.get(url);
  const headers = response.headers;

  return headers['last-modified'];
};
const createUrlElement = (url, lastmod, changefreq, priority) => {
  return {
    url,
    lastmod,
    changefreq,
    priority,
  };
};

getLastModified(getUrl('/'))
  .then((lastModified) => {
    const date = new Date(lastModified);
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();

    return `${year}-${month}-${day}`;
  });

console.log(convert.js2xml(sitemap, options));

@@ -822,16 +822,1260 @@
  %7D;%0A%7D;%0A%0A
+const urls = %5B%0A  %7B%0A    path: getUrl('/'),%0A    changefreq: changefreq.monthly,%0A    priority: '1.0',%0A  %7D,%0A  %7B%0A    path: getUrl('/train-number-calc.html'),%0A    changefreq: changefreq.monthly,%0A    priority: '0.8',%0A  %7D,%0A  %7B%0A    path: getUrl('/anime-push/'),%0A    changefreq: changefreq.yearly,%0A    priority: '0.8',%0A  %7D,%0A  %7B%0A    path: getUrl('/hk_sub_/'),%0A    changefreq: changefreq.yearly,%0A    priority: '0.4',%0A  %7D,%0A  %7B%0A    path: getUrl('/trysail-blog-notification/'),%0A    changefreq: changefreq.yearly,%0A    priority: '0.8',%0A  %7D,%0A  %7B%0A    path: getUrl('/trysail-blog-notification/plugin.html'),%0A    changefreq: changefreq.yearly,%0A    priority: '0.4',%0A  %7D,%0A  %7B%0A    path: getUrl('/console-wrapper/'),%0A    changefreq: changefreq.yearly,%0A    priority: '0.8',%0A  %7D,%0A  %7B%0A    path: getUrl('/HkApps/'),%0A    changefreq: changefreq.yearly,%0A    priority: '0.4',%0A  %7D,%0A  %7B%0A    path: getUrl('/SaveTweet/'),%0A    changefreq: changefreq.yearly,%0A    priority: '0.4',%0A  %7D,%0A  %7B%0A    path: getUrl('/ShortURL/'),%0A    changefreq: changefreq.yearly,%0A    priority: '0.4',%0A  %7D,%0A  %7B%0A    path: getUrl('/twitter-r4s/'),%0A    changefreq: changefreq.yearly,%0A    priority: '0.4',%0A  %7D,%0A  %7B%0A    path: getUrl('/CC-Lemon/'),%0A    changefreq: changefreq.yearly,%0A    priority: '0.4',%0A  %7D,%0A%5D;%0A%0A
 getLastM

Add urls