The fastest way β‘οΈ to create sitemap and robots.txt in your Deno Fresh project π
Attributes
Includes Deno configuration
Repository
Current version released
2 years ago
Fresh SEO πβββ
*Quickly creating sitemaps for your Deno Fresh project.*
Getting Started
Run the setup at the root of your project.
deno run \
--allow-read \
--allow-write \
https://deno.land/x/fresh_seo/init.ts
The following file should have been created:
routes/sitemap.xml.ts
A basic sitemap should now be available at:
http://localhost:8000/sitemap.xml
How does it work?
Fresh SEO π automatically maps out static routes in your project.
For basic routes, you do not have to do anything manually.
Dynamic Routes
You will still have to map dynamic routes yourself!
// ./routes/sitemap.xml.ts
import { SitemapContext } from 'https://deno.land/x/fresh_seo/mod.ts';
import { Handlers } from '$fresh/server.ts';
import manifest from '../fresh.gen.ts';
export const handler : Handlers = {
GET(request,context){
const sitemap = new SitemapContext(
'http://example.com'
manifest
);
// You can remove unwanted routes here
sitemap.add('/blog/hello-world');
return sitemap.render();
}
}
You can also remove unwanted routes
// ./routes/sitemap.xml.ts
import { SitemapContext } from 'https://deno.land/x/fresh_seo/mod.ts';
import { Handlers } from '$fresh/server.ts';
import manifest from '../fresh.gen.ts';
export const handler : Handlers = {
GET(request,context){
const sitemap = new SitemapContext(
'http://example.com'
manifest
);
// You can add additional page here
sitemap.remove('/gfm.css');
return sitemap.render();
}
}
Testing
The test suite can be started with
deno task test