Commit 06589a19 authored by Isabella Skořepová's avatar Isabella Skořepová
Browse files

Working redirect

parent 39250df3
......@@ -10,26 +10,43 @@ const config = require('./config')
module.exports = async (data, type_) => {
try {
// eslint-disable-next-line import/no-dynamic-require,global-require
const Template = require(path.join(
const templates = require(path.join(
process.cwd(),
config.themeDir,
'templates',
`${type_}.js`,
)).default
return [
{
content: ReactDOM.renderToStaticMarkup(
React.createElement(Template, {
...data,
config: {
...data.config,
baseurl: config ? config.options.baseurl : '',
},
}),
),
type: 'html',
return (Array.isArray(templates) ? templates : [templates]).map(
Template => {
const props = {
...data,
config: {
...data.config,
baseurl: config ? config.options.baseurl : '',
},
}
if ('type' in Template && Template.type === 'template') {
return {
content: Template.value(props),
type: Template.ext || 'html',
}
}
if ('type' in Template && Template.type === 'component') {
return {
content: ReactDOM.renderToStaticMarkup(
React.createElement(Template, props),
),
type: Template.ext || 'html',
}
}
return {
content: ReactDOM.renderToStaticMarkup(
React.createElement(Template, props),
),
type: 'html',
}
},
]
)
} catch (e) {
// temporary until I implement all templates
if (e.code === 'MODULE_NOT_FOUND') return []
......
export default [
{
type: 'template',
ext: 'php',
value: ({ config, content }) => {
return `<?php
header("HTTP/1.1 301 Moved Permanently");
header('location: ${config.baseurl}/${content}');`
},
},
{
type: 'template',
ext: 'html',
value: ({ config, content }) => `<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url=${config.baseurl}/${content}">
<script type="text/javascript">
window.location.href = "${config.baseurl}/${content}"
</script>
<title>Přesměrování...</title>
</head>
<body>
Pokud nebudete přesměrováni automaticky tak následujte <a href='${config.baseurl}/${content}'>tento odkaz</a>
</body>
</html>
`,
},
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment