Skip to content

Commit

Permalink
fix: generating for static hosting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mocca101 committed Mar 26, 2024
1 parent 31d0132 commit 83b21f8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
1 change: 1 addition & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default defineNuxtConfig({
compressPublicAssets: true,
prerender: {
routes: ["/manifest.webmanifest", "/robots.txt", "/sitemap.xml"],
failOnError: false,
},
},
postcss: {
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
"node": "20.x",
"pnpm": "8.x"
},
"packageManager": "[email protected].4",
"packageManager": "[email protected].5",
"scripts": {
"analyze": "nuxt analyze",
"build": "nuxt build --dotenv ./.env.local",
"generate": "pnpm generate:server && pnpm generate:reroute-index",
"generate:server": "nuxt generate --dotenv ./.env.local",
"generate:reroute-index": "tsx ./scripts/generate-reroute-index.ts",
"dev": "nuxt dev --dotenv ./.env.local",
"dev:cms": "decap-server",
"format:check": "prettier . \"!./content/**\" --cache --check --ignore-path ./.gitignore",
Expand Down Expand Up @@ -42,7 +45,7 @@
"@nuxt/content": "^2.12.0",
"@nuxt/image": "^1.3.0",
"@nuxtjs/color-mode": "^3.3.2",
"@nuxtjs/i18n": "^8.1.1",
"@nuxtjs/i18n": "^8.2.0",
"@nuxtjs/mdc": "^0.5.0",
"@stefanprobst/netlify-cms-oauth-client": "^0.4.0",
"@stefanprobst/openapi-client": "^0.0.3",
Expand Down
9 changes: 5 additions & 4 deletions pnpm-lock.yaml

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

17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ To properly configure OAuth, create a "GitHub OAuth App" at

The website is deployed via [GitHub action](./.github/workflows/build-deploy.yml).

Or it can be deployed manually:

As a (currently semi, as data is still being fetched from the API) static website:
```bash
pnpm run generate
```

The generated files are in the `.output/public/` directory.


As a node.js server:
```bash
pnpm run build
pnpm start
```


### Issues

To report bugs, or request new features, file an issue on our
Expand Down
27 changes: 27 additions & 0 deletions scripts/generate-reroute-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import fs from "fs";

import { defaultLocale, localesMap } from "../config/i18n.config";

console.log("Generating prerender index");

const dir = "./.output/public/";

if (Object.keys(localesMap).length <= 1) {
console.log("Single or no locales found, skipping rerout index generation");
}
if (Object.keys(localesMap).length > 1) {
console.log("Multiple locales found, generating reroute index");
const indexString = `<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; url=/${defaultLocale}/">
</head>
</html>`;

if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}

fs.writeFileSync(dir + "/index.html", indexString);
console.log("Reroute index generated");
}

0 comments on commit 83b21f8

Please sign in to comment.