Skip to content

Commit 465d542

Browse files
committed
dx: auto correct built output script
1 parent 9db65e8 commit 465d542

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

docs/_layout.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
</header>
1717
{{/showBack}}
1818
<article class='prose prose-zinc'>
19+
{{#title}}
20+
<h1 class=''>{{title}}</h1>
21+
{{/title}}
1922
{{{content}}}
2023
</article>
2124
<footer class='mt-10'>
@@ -25,6 +28,6 @@
2528
class='underline underline-offset-4'
2629
>tinytown.studio</a>
2730
</footer>
28-
<script src='highlight.mjs' type='module'></script>
31+
<script src='highlight.js' type='module'></script>
2932
</body>
3033
</html>

docs/guide.md

Lines changed: 0 additions & 1 deletion
This file was deleted.
File renamed without changes.

docs/index.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
A tiny pre-processor for tiny websites
44

5-
- [Getting Started](./getting-started)
6-
- [Guide](./guide)
5+
- [Quickstart](./quickstart)
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
---
2+
title: Quickstart
23
showBack: true
34
---
45

5-
# Getting Started
6-
7-
## Basics
8-
96
### Install
107

118
```sh
@@ -16,7 +13,7 @@ npm install -D @tinytown/pub
1613

1714
```sh
1815
# dev server
19-
npx -p @tinytown/pub pub ./src
16+
npx -p @tinytown/pub pu b ./src
2017

2118
# build assets
2219
npx -p @tinytown/pub pub ./dist

lib/publish.mjs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,32 @@ import glob from 'tiny-glob'
1414

1515
const compileTemplate = (layout) => (vars) => Mustache.render(layout, vars)
1616

17+
const htmlScriptReplacerPlugin = (tree) => {
18+
tree.walk((node) => {
19+
if (!node) return node
20+
if (node.tag !== 'script') return node
21+
22+
const currentSource = node.attrs['src']
23+
const sourceLink = currentSource.match(/^(\/?)((\w+\.?)+)/)
24+
if (!sourceLink) return node
25+
26+
const link = sourceLink[2]
27+
if (link.startsWith('http')) {
28+
return node
29+
}
30+
31+
node.attrs['src'] = node.attrs['src'].replace(
32+
extname(node.attrs['src']),
33+
'.mjs',
34+
)
35+
return node
36+
})
37+
}
38+
1739
const htmlProcessor = async (baseHTML, options) => {
1840
return (
1941
await posthtml([
42+
htmlScriptReplacerPlugin,
2043
posthtmlBaseURL({
2144
url: options.baseUrl,
2245
allTags: true,
@@ -163,7 +186,7 @@ export async function compile(basePath, distPath, options) {
163186
'.tsx': jsTransformer(transformerOptions),
164187
'.mjs': jsTransformer(transformerOptions),
165188
'.ts': jsTransformer(transformerOptions),
166-
'.scss': cssTransformer(transformerOptions),
189+
// '.scss': cssTransformer(transformerOptions),
167190
'.css': cssTransformer(transformerOptions),
168191
'.md': markdownTransfomer(transformerOptions),
169192
'.html': htmlTranformer(transformerOptions),

0 commit comments

Comments
 (0)