Skip to content

Commit 9dbffbf

Browse files
committed
🐛 Was treeding the 3.0 directory as an asset
Don't use the filename, use the content type to determine if something is an asset
1 parent b999405 commit 9dbffbf

File tree

7 files changed

+156
-138
lines changed

7 files changed

+156
-138
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/test/dist/
22
/statical
33
/dist/
4+
/staticalize

README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,28 @@
22

33
The framework agnostic static site generator.
44

5-
Every language has its own static site generator, and every static site generator is made obsolete by the next static site generator that comes along to replace it every few years. Staticalize lets you hop off that hamster wheel.
5+
Every language has its own static site generator, and every static site
6+
generator is made obsolete by the next static site generator that comes along to
7+
replace it every few years. Staticalize lets you hop off that hamster wheel.
68

7-
It does this by providing a _general_ mechanism to convert any dynamically generated website into a static one. It doesn't care _what_ framework you use to generate your content so long as it is served over HTTP and has a [sitemap][sitemap]. It will analyze your sitemap and generate a static website for it in the output directory of your choice. All you need to provide is url of the server you want to staticalize and the base url of your production server.
8-
9-
For example, if you have the sourcecode of the frontside.com website running on port `8000`, you can build a static version of the website fit to serve on `frontside.com` into the `dist/` directory with the following command:
9+
It does this by providing a _general_ mechanism to convert any dynamically
10+
generated website into a static one. It doesn't care _what_ framework you use to
11+
generate your content so long as it is served over HTTP and has a
12+
[sitemap][sitemap]. It will analyze your sitemap and generate a static website
13+
for it in the output directory of your choice. All you need to provide is url of
14+
the server you want to staticalize and the base url of your production server.
1015

16+
For example, if you have the sourcecode of the frontside.com website running on
17+
port `8000`, you can build a static version of the website fit to serve on
18+
`frontside.com` into the `dist/` directory with the following command:
1119

1220
```ts
1321
$ staticalize --site https://localhost:8000 --base-url http://frontside.com --outdir dist
1422
```
1523

16-
This will read `https://localhost:800/sitemap.xml` and download the entire website to the `dist/` directory in a format that can be served from a simple file server running at `frontside.com`.
17-
24+
This will read `https://localhost:800/sitemap.xml` and download the entire
25+
website to the `dist/` directory in a format that can be served from a simple
26+
file server running at `frontside.com`.
1827

1928
### CLI
2029

deno.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"tasks": {
33
"dev": "deno run --watch main.ts",
4-
"compile": "deno compile --allow-read --allow-write --allow-env --allow-sys --allow-run --allow-net -o statical main.ts"
4+
"compile": "deno compile --allow-read --allow-write --allow-env --allow-sys --allow-run --allow-net -o staticalize main.ts"
55
},
66
"imports": {
77
"@std/assert": "jsr:@std/assert@1",
@@ -10,7 +10,7 @@
1010
"@std/fs": "jsr:@std/fs",
1111
"@libs/xml": "jsr:@libs/xml",
1212
"deno-dom": "jsr:@b-fuze/deno-dom",
13-
"effection": "https://deno.land/x/effection@3.0.3/mod.ts"
13+
"effection": "npm:effection@4.0.0-alpha.4"
1414
},
1515
"lint": {
1616
"rules": {

deno.lock

Lines changed: 95 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staticalize.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,15 @@ function useDownloader(opts: DownloaderOptions): Operation<Downloader> {
105105
if (source.host !== host.host) {
106106
return;
107107
}
108-
let path = normalize(join(outdir, source.pathname));
109-
110-
if (path.endsWith("/") || !path.match(/\.\w+/)) {
111-
path = join(path, "index.html");
112-
}
113-
114-
let destpath = path.endsWith("/") || !path.match(/\.\w+/) ? join(path, "index.html") : path;
108+
let path = normalize(join(outdir, source.pathname));
115109

116110
yield* buffer.spawn(function* () {
117111
let response = yield* call(() =>
118112
fetch(source.toString(), { signal })
119113
);
120114
if (response.ok) {
121115
if (response.headers.get("Content-Type")?.includes("html")) {
116+
let destpath = join(path, "index.html");
122117
let content = yield* call(() => response.text());
123118
let document = new DOMParser().parseFromString(
124119
content,
@@ -146,6 +141,7 @@ function useDownloader(opts: DownloaderOptions): Operation<Downloader> {
146141
});
147142
} else {
148143
yield* call(async () => {
144+
let destpath = path;
149145
let destdir = dirname(destpath);
150146
await ensureDir(destdir);
151147
await Deno.writeFile(destpath, response.body!);

0 commit comments

Comments
 (0)