-
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.
feat: add sitemap and update workflows (#27)
- Loading branch information
Showing
6 changed files
with
95 additions
and
0 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
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 |
---|---|---|
|
@@ -30,3 +30,4 @@ coverage | |
*.tsbuildinfo | ||
|
||
public/pdfs/ | ||
public/sitemap.xml |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
User-agent: * | ||
Allow: / | ||
|
||
Sitemap: https://how-to.lookscanned.io/sitemap.xml |
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,48 @@ | ||
import { SitemapStream, streamToPromise } from 'sitemap' | ||
import { markdowns } from '../src/locales/how-to-use/markdowns' | ||
import { writeFile } from 'fs/promises' | ||
import { execSync } from 'child_process' | ||
|
||
const langs = Object.keys(markdowns) as (keyof typeof markdowns)[] | ||
const commitTimestamp = execSync('git log -1 --format=%at').toString().trim() | ||
const commitDate = new Date(parseInt(commitTimestamp) * 1000) | ||
const lastmod = commitDate.toISOString() | ||
|
||
const smStream = new SitemapStream({ | ||
hostname: 'https://how-to.lookscanned.io', | ||
lastmodDateOnly: false, | ||
xmlns: { | ||
// trim the xml namespace | ||
news: false, // flip to false to omit the xml namespace for news | ||
xhtml: true, | ||
image: false, | ||
video: false, | ||
}, | ||
}) | ||
|
||
const xmlBuffer = new Promise<Buffer>((resolve, reject) => { | ||
streamToPromise(smStream).then(resolve).catch(reject) | ||
}) | ||
|
||
smStream.write({ | ||
url: 'https://how-to.lookscanned.io', | ||
lastmod, | ||
}) | ||
|
||
for (const lang of langs) { | ||
smStream.write({ | ||
url: `https://how-to.lookscanned.io/how-to-use/${lang}`, | ||
lastmod, | ||
}) | ||
smStream.write({ | ||
url: `https://how-to.lookscanned.io/pdfs/how-to-use/${lang}.pdf`, | ||
lastmod, | ||
}) | ||
} | ||
|
||
smStream.end() | ||
|
||
const buffer = await xmlBuffer | ||
|
||
// write to ./public/sitemap.xml | ||
await writeFile('./public/sitemap.xml', buffer) |