-
Notifications
You must be signed in to change notification settings - Fork 710
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e8d178c
commit b05b8eb
Showing
10 changed files
with
161 additions
and
6 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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
{% extends 'base.html' %} | ||
{% set scripts = ("contribute",) %} | ||
|
||
{% block head_title %} | ||
{% include "pre-render" + path + ".head.html" %} | ||
{% endblock %} | ||
|
||
{% block contentwrap %} | ||
<div class="mzp-l-content" id="main-content"></div> | ||
<div class="mzp-l-content" id="main-content"> | ||
{% include "pre-render" + path + ".html" %} | ||
</div> | ||
{% endblock %} |
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
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
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
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,61 @@ | ||
const path = require("path"); | ||
const sveltePreprocess = require("svelte-preprocess"); | ||
const SveltePreRenderPlugin = require("./webpack/svelte-pre-render-plugin"); | ||
|
||
module.exports = { | ||
entry: { | ||
contribute: "./svelte/contribute/Contribute", | ||
}, | ||
plugins: [ | ||
new SveltePreRenderPlugin({ | ||
"contribute.js": [ | ||
"/contribute", | ||
"/contribute/forum", | ||
"/contribute/kb", | ||
"/contribute/social", | ||
] | ||
}) | ||
], | ||
mode: "production", | ||
resolve: { | ||
alias: { | ||
svelte: path.resolve("node_modules", "svelte"), | ||
}, | ||
extensions: [".mjs", ".js", ".svelte"], | ||
mainFields: ["svelte", "browser", "module", "main"], | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.svelte$/, | ||
use: { | ||
loader: "svelte-loader", | ||
options: { | ||
emitCss: false, | ||
preprocess: sveltePreprocess(), | ||
compilerOptions: { | ||
generate: "ssr", | ||
hydratable: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
// required to prevent errors from Svelte on Webpack 5+, omit on Webpack 4 | ||
test: /node_modules\/svelte\/.*\.mjs$/, | ||
resolve: { | ||
fullySpecified: false, | ||
}, | ||
}, | ||
], | ||
}, | ||
devtool: "cheap-module-source-map", | ||
output: { | ||
filename: "[name].js", | ||
path: path.resolve(__dirname, "dist/pre-render"), | ||
library: { | ||
type: "commonjs", | ||
}, | ||
}, | ||
target: "node", | ||
}; |
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,59 @@ | ||
const fs = require("fs"); | ||
|
||
function rerequire(path) { | ||
delete require.cache[path]; | ||
return require(path); | ||
} | ||
|
||
class SveltePreRenderPlugin { | ||
constructor(options = {}) { | ||
this.options = options; | ||
} | ||
|
||
apply(compiler) { | ||
const locales = fs.readdirSync("jsi18n/jsi18n"); | ||
|
||
compiler.hooks.assetEmitted.tap( | ||
"svelte-pre-render-plugin", | ||
(file, { outputPath, targetPath }) => { | ||
const routes = this.options[file]; | ||
if (routes) { | ||
const Component = rerequire(targetPath).default; | ||
|
||
for (const locale of locales) { | ||
const jsi18n = rerequire(`../jsi18n/jsi18n/${locale}/djangojs.js`); | ||
Object.assign(global, jsi18n); | ||
|
||
for (const route of routes) { | ||
const { head = "", html } = Component.render({ | ||
url: `/${locale}${route}`, | ||
locale, | ||
}); | ||
|
||
fs.mkdirSync( | ||
`${outputPath}/${locale}${route | ||
.split("/") | ||
.slice(0, -1) | ||
.join("/")}`, | ||
{ | ||
recursive: true, | ||
} | ||
); | ||
|
||
fs.writeFileSync( | ||
`${outputPath}/${locale}${route}.head.html`, | ||
head | ||
); | ||
fs.writeFileSync( | ||
`${outputPath}/${locale}${route}.html`, | ||
html | ||
); | ||
} | ||
} | ||
} | ||
} | ||
); | ||
} | ||
} | ||
|
||
module.exports = SveltePreRenderPlugin; |