Skip to content

Commit 9b425c5

Browse files
authored
Merge branch 'main' into iso-router-reset-scroll
2 parents ef7df42 + 3954ddb commit 9b425c5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+2667
-314
lines changed

.changeset/dull-bags-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wmr": patch
3+
---
4+
5+
Bugfix: Fix a crash when prerendering encounters an error, and show pretty-printed stack traces instead.

.changeset/mean-cycles-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wmr": patch
3+
---
4+
5+
Bugfix: fixes a crash when initializing Chokidar on some systems

.changeset/odd-singers-explode.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"preact-iso": patch
3+
---
4+
5+
Bugfix: fix route flashing for routes that render fragments

.changeset/yellow-peas-decide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"preact-iso": patch
3+
---
4+
5+
[preact-iso] Prevent the Router from intercepting clicks on links with an "external" target (`target="anything"`).

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ Steps to reproduce the behavior:
2525
A clear and concise description of what you expected to happen.
2626

2727
**Desktop (please complete the following information):**
28-
- OS: [e.g. iOS]
29-
- Browser [e.g. chrome, safari]
30-
- WMR Version [e.g. 22]
28+
- OS: [e.g. MacOS 11.2.3, Windows 10]
29+
- Browser: [e.g. chrome, safari]
30+
- Node Version: [e.g. 15.8]
31+
- WMR Version: [e.g. 1.3.1]
3132

3233
**Additional context**
3334
Add any other context about the problem here.

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ jobs:
4949
- name: Test wmr
5050
if: ${{ needs.changes.outputs.wmr == 'true' }}
5151
run: yarn workspace wmr test
52+
- name: Test wmr (production build)
53+
if: ${{ needs.changes.outputs.wmr == 'true' }}
54+
run: yarn workspace wmr test-prod
5255
- name: Test preact-iso
5356
if: ${{ needs.changes.outputs.preact-iso == 'true' }}
5457
run: yarn workspace preact-iso test

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# WMR
22

3+
<img src="./docs/public/assets/wmr.svg" alt="wmr logo" width="400">
4+
35
[![npm](https://img.shields.io/npm/v/wmr.svg)](http://npm.im/wmr)
46
[![install size](https://packagephobia.com/badge?p=wmr)](https://packagephobia.com/result?p=wmr)
57
[![OpenCollective Backers](https://opencollective.com/preact/backers/badge.svg)](#backers)
@@ -33,7 +35,7 @@ or
3335
<strong><code>yarn create wmr your-project-name</code></strong>
3436

3537
<p>
36-
<img width="400" src="https://user-images.githubusercontent.com/105127/100917537-4661e100-34a5-11eb-89bd-565b7bc31919.gif">
38+
<img width="400" src="https://user-images.githubusercontent.com/105127/100917537-4661e100-34a5-11eb-89bd-565b7bc31919.gif" alt="illustartion of installation to build for wmr">
3739
</p>
3840

3941
> 💁 If you'd like ESLint to be set up for you, add `--eslint` to the command. _Note: this will use 150mb of disk space._

docs/global.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
declare module 'content:*' {
2+
interface Item {
3+
name: string;
4+
nav?: string;
5+
title?: string;
6+
description?: string;
7+
image?: string;
8+
[key: string]: string;
9+
}
10+
const Data: Item[];
11+
export = Data;
12+
}
13+
14+
declare module 'markdown:*' {
15+
const Url: string;
16+
export = Url;
17+
}

docs/package.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
{
2-
"name": "@wmr/docs",
2+
"name": "docs",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
36
"scripts": {
4-
"dev": "wmr",
5-
"build": "wmr build --prerender"
7+
"start": "wmr",
8+
"build": "if-env NETLIFY=true && node --experimental-modules ../packages/wmr/src/cli.js build --prerender || wmr build --prerender",
9+
"serve": "wmr serve"
10+
},
11+
"dependencies": {
12+
"preact": "^10.5.13",
13+
"preact-iso": "*",
14+
"preact-markup": "^2.1.1"
615
},
716
"devDependencies": {
8-
"@wmr-plugins/directory-import": "0.1.1",
9-
"wmr": "1.3.2"
17+
"@wmr-plugins/directory-import": "*",
18+
"if-env": "^1.0.4",
19+
"marked": "^2.0.1",
20+
"wmr": "*",
21+
"yaml": "^1.10.2"
1022
}
1123
}

docs/plugins/content.js

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import marked from 'marked';
2+
import { promises as fs } from 'fs';
3+
import path from 'path';
4+
import yaml from 'yaml';
5+
6+
export default function contentPlugin(config, opts) {
7+
config.plugins.push(contentRollupPlugin({ ...config, ...opts }));
8+
}
9+
contentPlugin.rollup = contentRollupPlugin;
10+
11+
async function tree(dir, prefix = '') {
12+
const entries = await fs.readdir(dir, { withFileTypes: true });
13+
const list = await Promise.all(
14+
entries.map(entry => {
15+
if (entry[0] === '.') return;
16+
const name = (prefix ? prefix + '/' : '') + entry.name;
17+
if (entry.isDirectory()) return tree(path.join(dir, entry.name), name);
18+
return name;
19+
})
20+
);
21+
return list.flat().filter(Boolean);
22+
}
23+
24+
const FRONT_MATTER_REG = /^\s*---\n\s*([\s\S]*?)\s*\n---\n/i;
25+
const TITLE_REG = /^\s*#\s+(.+)\n+/;
26+
async function getMeta(filename) {
27+
let meta = {};
28+
let content = await fs.readFile(filename, 'utf-8');
29+
content = content.replace(FRONT_MATTER_REG, (s, fm) => {
30+
meta = yaml.parse('---\n' + fm.replace(/^/gm, ' ') + '\n') || meta;
31+
return '';
32+
});
33+
content = content.replace(TITLE_REG, s => {
34+
if (!meta.title) meta.title = s;
35+
return '';
36+
});
37+
content = decodeHtmlEntities(marked(content));
38+
if (!meta.description) {
39+
let stripped = content.replace(/(?:<(figcaption)[^>]*?>.*?<\/\1>|<.*?>|(?:^|\n)>)/g, '').trim();
40+
let desc = stripped.match(/[^\n]+/g)[0];
41+
if (desc && desc.length > 200) desc = desc.slice(0, 199) + '…';
42+
meta.description = desc;
43+
}
44+
if (
45+
meta.published &&
46+
meta.updated &&
47+
meta.published.replace(/:\d\d:\d\d/, '') === meta.updated.replace(/:\d\d:\d\d/, '')
48+
)
49+
delete meta.updated;
50+
if (meta.description === meta.meta_description) delete meta.meta_description;
51+
if (meta.title === meta.meta_title) delete meta.meta_title;
52+
for (let i in meta) if (i[0] === '.' || i[0] === '_') delete meta[i];
53+
// we could return all the metadata here, but it's currently unused:
54+
// return meta;
55+
return {
56+
nav: meta.nav || meta.title
57+
};
58+
}
59+
60+
function decodeHtmlEntities(html) {
61+
return html.replace(/&(?:#(\d+)|times|apos|quot|amp);/g, (s, n, t) => {
62+
switch (t) {
63+
case 'times':
64+
return '×';
65+
case 'apos':
66+
return 'ʼ';
67+
case 'quot':
68+
return '"';
69+
case 'amp':
70+
return '&';
71+
}
72+
return String.fromCharCode(n);
73+
});
74+
}
75+
76+
/**
77+
* markdown blog/content plugin for Rollup / WMR
78+
*/
79+
function contentRollupPlugin({ cwd, prod, ...opts }) {
80+
return {
81+
name: 'content',
82+
async resolveId(id, importer) {
83+
if (id[0] === '\0' || !id.startsWith('content:')) return;
84+
id = id.slice(8);
85+
if (importer) importer = importer.replace(/^[\0\b]\w+:/g, '');
86+
let resolved = await this.resolve(id, importer, { skipSelf: true });
87+
if (!resolved) {
88+
const r = path.join(path.dirname(importer), id);
89+
const s = await fs.stat(r).catch(() => null);
90+
if (s && s.isDirectory()) resolved = { id: r };
91+
}
92+
if (resolved) return '\0content:' + resolved.id.replace(/\/\.$/, '');
93+
},
94+
async load(id) {
95+
if (!id.startsWith('\0content:')) return;
96+
id = path.resolve(cwd || '.', id.slice(9));
97+
const files = (await tree(id)).filter(file => file.endsWith('.md'));
98+
const data = await Promise.all(
99+
files.map(async file => {
100+
const { slug, ...meta } = await getMeta(path.resolve(id, file));
101+
return { name: slug || file.replace(/\.md$/, ''), ...meta };
102+
})
103+
);
104+
data.sort((a, b) => +new Date(b.published) - +new Date(a.published));
105+
106+
let imports = '';
107+
108+
const serializeItem = item => {
109+
const url = 'markdown:./' + path.posix.relative(path.dirname(id), path.resolve(id, item.name)) + '.md';
110+
imports += `import ${JSON.stringify(url)};\n`;
111+
112+
let str = '{ ';
113+
for (let i in item) if (item[i] != null) str += `${i}: ${JSON.stringify(item[i])}, `;
114+
return str + '}';
115+
};
116+
117+
const code = 'export default [' + data.map(serializeItem).join(',\n') + '];';
118+
return imports + code;
119+
}
120+
};
121+
}

0 commit comments

Comments
 (0)