Skip to content

Commit

Permalink
πŸš€ SiteMap with robots.txt file (#34)
Browse files Browse the repository at this point in the history
* πŸš€ 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
payapula authored Aug 22, 2021
1 parent 9fbcf1c commit a42ea38
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 0 deletions.
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"remark": "11.0.2",
"remark-html": "10.0.0",
"sharp": "^0.29.0",
"sitemap": "^7.0.0",
"typescript": "^4.3.5"
},
"devDependencies": {
Expand Down
63 changes: 63 additions & 0 deletions pages/api/posts-sitemap.js
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));
}
};
2 changes: 2 additions & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
User-agent: *
Sitemap: https://bharathikannan.com/api/posts-sitemap

1 comment on commit a42ea38

@vercel
Copy link

@vercel vercel bot commented on a42ea38 Aug 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.