-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
not able to locate file [currently working on it]
- Loading branch information
Showing
1 changed file
with
68 additions
and
53 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,65 +1,80 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import { | ||
getEpisodes, | ||
} from '../src/data/podcast'; | ||
import { getNewsletter } from '../src/data/newsletters'; | ||
|
||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
function sitemap() { | ||
return [ | ||
{ | ||
url: 'https://virtualcoffee.io', | ||
lastModified: new Date(), | ||
changeFrequency: 'yearly', | ||
priority: 1, | ||
}, | ||
{ | ||
url: 'https://virtualcoffee.io/about', | ||
lastModified: new Date(), | ||
changeFrequency: 'monthly', | ||
priority: 0.8, | ||
}, | ||
{ | ||
url: 'https://virtualcoffee.io/events', | ||
lastModified: new Date(), | ||
changeFrequency: 'weekly', | ||
priority: 0.6, | ||
}, | ||
{ | ||
url: 'https://virtualcoffee.io/podcast', | ||
lastModified: new Date(), | ||
changeFrequency: 'monthly', | ||
priority: 0.7, | ||
}, | ||
{ | ||
url: 'https://virtualcoffee.io/contact', | ||
lastModified: new Date(), | ||
changeFrequency: 'yearly', | ||
priority: 0.4, | ||
}, | ||
]; | ||
async function generateStaticParams() { | ||
const newsletters = await getNewsletter(); | ||
const podcasts = await getEpisodes(); | ||
|
||
|
||
const newsletterUrls = newsletters.map(newsletter => ({ | ||
href: newsletter.href, | ||
lastModified: newsletter.lastModified, | ||
})); | ||
const podcastUrls = podcasts.map(podcast => ({ | ||
href: podcast.href, | ||
lastModified: podcast.lastModified, // Ensure you have this field in your data | ||
})); | ||
|
||
return { | ||
newsletters: newsletterUrls, | ||
podcasts: podcastUrls, | ||
}; | ||
} | ||
|
||
async function sitemap() { | ||
const newsletters = await generateStaticParams(); | ||
|
||
const newsletterUrls = newsletters.map(newsletter => ({ | ||
url: `https://virtualcoffee.io/newsletter/issues/${newsletter.href.replace('/newsletter/issues/', '')}`, | ||
lastModified: new Date(newsletter.lastModified), | ||
changeFrequency: 'monthly', | ||
priority: 0.7, | ||
})); | ||
|
||
return [ | ||
{ | ||
url: 'https://virtualcoffee.io', | ||
lastModified: new Date(), | ||
changeFrequency: 'yearly', | ||
priority: 1, | ||
}, | ||
{ | ||
url: 'https://virtualcoffee.io/about', | ||
lastModified: new Date(), | ||
changeFrequency: 'monthly', | ||
priority: 0.8, | ||
}, | ||
...newsletterUrls, | ||
]; | ||
} | ||
|
||
console.log('Generating sitemap...'); | ||
(async () => { | ||
console.log('Generating sitemap...'); | ||
|
||
const sitemapContent = sitemap() | ||
.map( | ||
(entry) => ` | ||
<url> | ||
<loc>${entry.url}</loc> | ||
<lastmod>${entry.lastModified.toISOString()}</lastmod> | ||
<changefreq>${entry.changeFrequency}</changefreq> | ||
<priority>${entry.priority}</priority> | ||
</url> | ||
`, | ||
) | ||
.join(''); | ||
const sitemapContent = (await sitemap()).map(entry => ` | ||
<url> | ||
<loc>${entry.url}</loc> | ||
<lastmod>${entry.lastModified.toISOString()}</lastmod> | ||
<changefreq>${entry.changeFrequency}</changefreq> | ||
<priority>${entry.priority}</priority> | ||
</url> | ||
`).join(''); | ||
|
||
const sitemapXml = `<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
${sitemapContent} | ||
</urlset>`; | ||
const sitemapXml = `<?xml version="1.0" encoding="UTF-8"?> | ||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> | ||
${sitemapContent} | ||
</urlset>`; | ||
|
||
const outputPath = path.join(__dirname, '../public/sitemap.xml'); | ||
fs.writeFileSync(outputPath, sitemapXml, 'utf8'); | ||
console.log(`Sitemap generated successfully at ${outputPath}`); | ||
const outputPath = path.join(__dirname, '../public/sitemap.xml'); | ||
fs.writeFileSync(outputPath, sitemapXml, 'utf8'); | ||
console.log(`Sitemap generated successfully at ${outputPath}`); | ||
})(); |