Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/CodeEditApp/codeedit.app in…
Browse files Browse the repository at this point in the history
…to dev
  • Loading branch information
austincondiff committed Sep 27, 2022
2 parents 520b721 + 34fd754 commit 4970ba4
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
"lint": "next lint",
"postbuild": "NODE_OPTIONS='--experimental-json-modules' node ./scripts/generate-sitemap.mjs"
},
"dependencies": {
"next": "12.1.0",
Expand All @@ -13,7 +14,9 @@
"react-dom": "17.0.2",
"react-feather": "^2.0.10",
"react-parallax": "^3.5.1",
"styled-components": "^5.3.5"
"styled-components": "^5.3.5",
"prettier": "^2.5.1",
"globby": "13.1.2"
},
"devDependencies": {
"eslint": "8.9.0",
Expand Down
Binary file modified public/favicon.ico
Binary file not shown.
2 changes: 2 additions & 0 deletions public/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> </urlset>
47 changes: 47 additions & 0 deletions scripts/generate-sitemap.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { writeFileSync } from 'fs'

import { globby } from 'globby'
import prettier from 'prettier'

async function generate() {
const prettierConfig = await prettier.resolveConfig('./.prettierrc.js')
const pages = await globby([
'pages/*.tsx',
'data/**/*.mdx',
'!data/*.mdx',
'!pages/_*.tsx',
'!pages/api',
'!pages/404.tsx',
])

const sitemap = `
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
${pages
.map(page => {
const path = page
.replace('pages', '')
.replace('data', '')
.replace('.tsx', '')
.replace('.mdx', '')
const route = path === '/index' ? '' : path
return `
<url>
<loc>${`https://cretu.dev${route}`}</loc>
</url>
`
})
.join('')}
</urlset>
`

const formatted = prettier.format(sitemap, {
...prettierConfig,
parser: 'html',
})

// eslint-disable-next-line no-sync
writeFileSync('public/sitemap.xml', formatted)
}

generate()

0 comments on commit 4970ba4

Please sign in to comment.