-
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.
- Loading branch information
Showing
4 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,102 @@ | ||
const SITEMAP_HOSTNAME = "https://clubs.iiit.ac.in"; | ||
|
||
const fs = require("node:fs"); | ||
const { SitemapStream, streamToPromise } = require("sitemap"); | ||
const { Readable } = require("stream"); | ||
|
||
const APP_ROOT = "./src/app"; | ||
const PAGE_FILENAME = "page.jsx"; | ||
const SITEMAP_PATHS = []; | ||
// const TODAYS_DATE_AS_ARRAY = new Date().toLocaleDateString().split("/"); | ||
const WRITE_FILE_PATH = "./src/app/sitemap.xml"; | ||
/** | ||
* Populates [SITEMAP_PATHS] with the fully qualified URLs for our pages to be contained | ||
* within our sitemap.xml file. | ||
* | ||
* @param {string} path The path we are currently searching. | ||
* @param {string} isRoot Flag that denotes whether or not we are processing our root path. | ||
* @return {void} | ||
*/ | ||
const getAllUrlsForSitemap = (path, isRoot) => { | ||
// Get all files within our current directory | ||
const files = fs.readdirSync(path); | ||
files.forEach((file) => { | ||
// Not using template strings due to article format on website. | ||
const dirPath = path + "/" + file; | ||
if (file.includes(PAGE_FILENAME) && !isRoot) { | ||
SITEMAP_PATHS.push(dirPath); | ||
} else { | ||
try { | ||
const stats = fs.statSync(dirPath); | ||
if (stats.isDirectory()) { | ||
// Continue searching until we exhaust all directories. | ||
getAllUrlsForSitemap(dirPath, false); | ||
} | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
} | ||
}); | ||
}; | ||
|
||
const makeDate = (datetime) => { | ||
return new Date(datetime).toISOString(); | ||
}; | ||
|
||
/** | ||
* Returns an object containing the url and lastmod sitemap properties. | ||
* | ||
* @param {string} path The path we are currently searching. | ||
* @param {string} isRoot Flag that denotes whether or not we are processing our root path. | ||
* @return {Object} url: URL for page on website. lastmod: last modification date for our page. | ||
*/ | ||
const mapToSitemapFormat = (path) => ({ | ||
// Not using template strings due to article format on website. | ||
url: path.replace(APP_ROOT + "/", "").replace("/" + PAGE_FILENAME, ""), | ||
// lastmod: makeDate(fs.statSync(path).mtime.toLocaleString()), | ||
lastmod: require("child_process") | ||
.execSync(`git log -1 --pretty="format:%ci" ${path}`) | ||
.toString() | ||
.trim(), | ||
}); | ||
/** | ||
* Returns a string representation of a date unit. e.g. dd, mm, yy | ||
* | ||
* @param {string} unit Date unit as a number in string format. e.g. month, day, year | ||
* @param {string} isRoot Flag that denotes whether or not we are processing our root path. | ||
* @return {Object} url: URL for page on website. lastmod: last modification date for our page. | ||
*/ | ||
// const padDateUnit = (unit) => ("unit".length < 2 ? "0" + "unit" : unit); | ||
(async () => { | ||
console.info("Generating sitemap..."); | ||
// Create [SitemapStream] that will ultimately populate our sitemap.xml. | ||
const stream = new SitemapStream({ | ||
hostname: SITEMAP_HOSTNAME, | ||
}); | ||
// Populate [SITEMAP_PATHS] based on our [PAGE_FILENAME]. | ||
getAllUrlsForSitemap(APP_ROOT, true); | ||
try { | ||
// Create our sitemap.xml contents. | ||
const ROOT_SITEMAP_ENTRY = { | ||
url: SITEMAP_HOSTNAME, | ||
lastmod: makeDate( | ||
fs | ||
.statSync(APP_ROOT + "/" + PAGE_FILENAME) | ||
.mtime.toLocaleString() | ||
// .split("/") | ||
), | ||
}; | ||
const content = await streamToPromise( | ||
Readable.from([ | ||
ROOT_SITEMAP_ENTRY, | ||
...SITEMAP_PATHS.map((url) => mapToSitemapFormat(url)), | ||
]).pipe(stream) | ||
).then((data) => data.toString()); | ||
console.info("Successfully generated sitemap..."); | ||
|
||
// Write our sitemap contents to [WRITE_FILE_PATH]. | ||
fs.writeFileSync(WRITE_FILE_PATH, content); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
})(); |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"><url><loc>https://clubs.iiit.ac.in/</loc><lastmod>2024-03-23T09:47:08.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/about/clubs-council/cc-members</loc><lastmod>2024-03-17T08:08:49.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/about/clubs-council</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/about/clubs-council/tech-members</loc><lastmod>2024-03-17T08:08:49.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/about/supervisory-bodies</loc><lastmod>2023-08-04T23:43:11.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/buzz-schedule</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/calendar</loc><lastmod>2024-01-06T10:16:37.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/cc-team-24-25</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/changelog</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/clubs/[id]/members</loc><lastmod>2024-02-01T05:26:44.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/clubs/[id]</loc><lastmod>2024-02-01T05:26:44.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/clubs</loc><lastmod>2024-01-06T09:02:10.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/events/[id]</loc><lastmod>2024-02-01T05:26:44.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/events</loc><lastmod>2023-08-03T09:43:48.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/gallery</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/clubs/[id]/edit</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/clubs/[id]</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/clubs/new</loc><lastmod>2023-08-05T23:06:34.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/clubs</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/events/[id]/approve_cc</loc><lastmod>2024-03-23T18:11:58.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/events/[id]/copy</loc><lastmod>2024-03-12T05:49:21.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/events/[id]/edit</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/events/[id]</loc><lastmod>2024-03-12T05:56:10.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/events/code/[code]</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/events/new</loc><lastmod>2023-10-02T20:55:15.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/events</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/members/[id]/edit</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/members/[id]</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/members/new</loc><lastmod>2023-07-30T20:46:51.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/manage/members</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/profile/[id]/edit</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/profile/[id]</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/profile</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/recruitment-calendar</loc><lastmod>2024-03-12T04:00:35.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/student-bodies/[id]/members</loc><lastmod>2023-07-27T13:31:58.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/student-bodies/[id]</loc><lastmod>2024-01-28T06:22:39.000Z</lastmod></url><url><loc>https://clubs.iiit.ac.in/student-bodies</loc><lastmod>2024-01-06T13:14:05.000Z</lastmod></url></urlset> |