Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions package-lock.json

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

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
},
"dependencies": {
"preact": "^10.5.12",
"preact-iso": "^2.0.0"
"preact-iso": "^2.0.3"
},
"devDependencies": {
"@wmr-plugins/directory-import": "^0.1.1",
"@wmr-plugins/directory-import": "^0.1.2",
"eslint": "^7.22.0",
"eslint-config-preact": "^1.1.3",
"eslint-config-prettier": "^8.1.0",
Expand All @@ -58,7 +58,7 @@
"marked": "^2.0.1",
"prettier": "^2.2.1",
"sass": "^1.32.12",
"wmr": "^1.7.0",
"wmr": "^3.0.1",
"yaml": "^1.10.2"
}
}
4 changes: 2 additions & 2 deletions plugins/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async function getMeta(filename) {
/**
* markdown blog/content plugin for Rollup / WMR
*/
function contentRollupPlugin({ cwd, prod, ...opts }) {
function contentRollupPlugin({ root, prod, ...opts }) {
return {
name: 'content',
async resolveId(id, importer) {
Expand Down Expand Up @@ -98,7 +98,7 @@ function contentRollupPlugin({ cwd, prod, ...opts }) {
},
async load(id) {
if (!id.startsWith('\0content:')) return;
id = path.resolve(cwd || '.', id.slice(9));
id = path.resolve(root || '.', id.slice(9));

// const base = path.relative(cwd || '.', id);
const files = await tree(id);
Expand Down
12 changes: 6 additions & 6 deletions plugins/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import yaml from 'yaml';
import { promises as fs } from 'fs';
import path from 'path';

export default function markdownPlugin({ plugins, cwd, prod }, opts) {
plugins.push(markdownRollupPlugin({ cwd, prod, ...opts }));
export default function markdownPlugin({ plugins, root, prod }, opts) {
plugins.push(markdownRollupPlugin({ root, prod, ...opts }));
}
markdownPlugin.rollup = markdownRollupPlugin;

Expand Down Expand Up @@ -39,7 +39,7 @@ async function processMarkdown(filename, opts) {
* @example
* import html from 'markdown:./pages';
*/
function markdownRollupPlugin({ cwd, prod, ...opts }) {
function markdownRollupPlugin({ root, prod, ...opts }) {
return {
name: 'markdown',
async resolveId(id, importer) {
Expand Down Expand Up @@ -75,7 +75,7 @@ function markdownRollupPlugin({ cwd, prod, ...opts }) {
// return `export default ${JSON.stringify(html)}`;

if (!id.startsWith('\0markdown:')) return;
id = path.resolve(cwd || '.', id.slice(10));
id = path.resolve(root || '.', id.slice(10));

this.addWatchFile(id);
const html = await processMarkdown(id, opts);
Expand All @@ -87,8 +87,8 @@ function markdownRollupPlugin({ cwd, prod, ...opts }) {
// console.log(path.relative(cwd || '.', id));
const fileId = this.emitFile({
type: 'asset',
name: path.relative(cwd || '.', id),
fileName: path.relative(cwd || '.', id),
name: path.relative(root || '.', id),
fileName: path.relative(root || '.', id),
source: html
});
return `export default import.meta.ROLLUP_FILE_URL_${fileId}`;
Expand Down
2 changes: 1 addition & 1 deletion public/components/Home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import styles from './style.module.scss';

export default function Home() {
if (typeof window === 'undefined') {
document.head.insertAdjacentHTML('beforeend', `<link rel="preload" as="image" href="${config.cover}">`);
wmrHead.elements.push(`<link rel="preload" as="image" href="${config.cover}">`);
}
return (
<section class="home">
Expand Down
11 changes: 10 additions & 1 deletion public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ export async function prerender(data) {
const text = () => fs.readFile('dist/' + String(url).replace(/^\//, ''), 'utf-8');
return { text, json: () => text().then(JSON.parse) };
};
global.wmrHead = {
title: undefined,
lang: undefined,
elements: []
};
const { default: prerender } = await import('preact-iso/prerender');
return await prerender(<App {...data} />);
const res = await prerender(<App {...data} />);
return {
...res,
head: global.wmrHead
};
}