-
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.
π SiteMap with robots.txt file (#34)
* π NextJs Update, Image Enhancements & Lighthouse 100 * Fixes of Title in Slug Page, Removed Comments. Added ALT text correctly for Chakra post. * Updatex next to 11.1.0 added blur property for autho URL * Added `plaiceholder` package to dynamically add blur64 to next/image (For Post covers). * Added Github URL to Website footer. Added Lets Discuss on twitter URL in posts. Fixed GMAIL toasts on Posts Homepage * Removed Client only rendering of footer, and handled access to window.navigator in UseEffect. Now the footer renders without javascript for better SEO. * Added gradient color to Blog Posts homepage text 'Posts' * Lighouse corrections, 100% on Desktop * Superlinter definition not found fixed * Version updated to 1.1.0. SEO Changes. * Added SiteMap and robots file * Added new line at the End of Robots File
- Loading branch information
Showing
4 changed files
with
102 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,63 @@ | ||
import { SitemapStream, streamToPromise } from 'sitemap'; | ||
|
||
/** | ||
* REFER : https://linguinecode.com/post/add-robots-txt-file-sitemaps-nextjs | ||
* Added SiteMap to robots.txt file as well | ||
*/ | ||
// eslint-disable-next-line | ||
export default async (req, res) => { | ||
try { | ||
const smStream = new SitemapStream({ | ||
hostname: `https://${req.headers.host}`, | ||
cacheTime: 600000 | ||
}); | ||
|
||
// List of posts | ||
const posts = [ | ||
{ url: 'minimizing-lodash-bundle-size' }, | ||
{ url: 'simple-introduction-to-chakra' }, | ||
{ | ||
url: 'react-hooks-dependencies-and-stale-closures' | ||
}, | ||
{ url: 'react-useeffect-flow' }, | ||
{ url: 'react-is-just-javascript' } | ||
]; | ||
|
||
smStream.write({ | ||
url: `https://${req.headers.host}`, | ||
changefreq: 'daily', | ||
priority: 0.9 | ||
}); | ||
|
||
// Create each URL row | ||
posts.forEach((post) => { | ||
smStream.write({ | ||
url: `/blog/${post.url}`, | ||
changefreq: 'daily', | ||
priority: 0.9 | ||
}); | ||
}); | ||
|
||
smStream.write({ | ||
url: `https://${req.headers.host}/blog`, | ||
changefreq: 'daily', | ||
priority: 0.9 | ||
}); | ||
|
||
// End sitemap stream | ||
smStream.end(); | ||
|
||
// XML sitemap string | ||
const sitemapOutput = (await streamToPromise(smStream)).toString(); | ||
|
||
// Change headers | ||
res.writeHead(200, { | ||
'Content-Type': 'application/xml' | ||
}); | ||
|
||
// Display output to user | ||
res.end(sitemapOutput); | ||
} catch (e) { | ||
res.send(JSON.stringify(e)); | ||
} | ||
}; |
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,2 @@ | ||
User-agent: * | ||
Sitemap: https://bharathikannan.com/api/posts-sitemap |
a42ea38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: