Skip to content

Commit

Permalink
🐛 Was treeding the 3.0 directory as an asset
Browse files Browse the repository at this point in the history
Don't use the filename, use the content type to determine if something
is an asset
  • Loading branch information
cowboyd committed Jan 14, 2025
1 parent b999405 commit 9dbffbf
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 138 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/test/dist/
/statical
/dist/
/staticalize
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,28 @@

The framework agnostic static site generator.

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.
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.

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.

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:
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.

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:

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

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`.

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`.

### CLI

Expand Down
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"tasks": {
"dev": "deno run --watch main.ts",
"compile": "deno compile --allow-read --allow-write --allow-env --allow-sys --allow-run --allow-net -o statical main.ts"
"compile": "deno compile --allow-read --allow-write --allow-env --allow-sys --allow-run --allow-net -o staticalize main.ts"
},
"imports": {
"@std/assert": "jsr:@std/assert@1",
Expand All @@ -10,7 +10,7 @@
"@std/fs": "jsr:@std/fs",
"@libs/xml": "jsr:@libs/xml",
"deno-dom": "jsr:@b-fuze/deno-dom",
"effection": "https://deno.land/x/effection@3.0.3/mod.ts"
"effection": "npm:effection@4.0.0-alpha.4"
},
"lint": {
"rules": {
Expand Down
190 changes: 95 additions & 95 deletions deno.lock

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

10 changes: 3 additions & 7 deletions staticalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,15 @@ function useDownloader(opts: DownloaderOptions): Operation<Downloader> {
if (source.host !== host.host) {
return;
}
let path = normalize(join(outdir, source.pathname));

if (path.endsWith("/") || !path.match(/\.\w+/)) {
path = join(path, "index.html");
}

let destpath = path.endsWith("/") || !path.match(/\.\w+/) ? join(path, "index.html") : path;
let path = normalize(join(outdir, source.pathname));

yield* buffer.spawn(function* () {
let response = yield* call(() =>
fetch(source.toString(), { signal })
);
if (response.ok) {
if (response.headers.get("Content-Type")?.includes("html")) {
let destpath = join(path, "index.html");
let content = yield* call(() => response.text());
let document = new DOMParser().parseFromString(
content,
Expand Down Expand Up @@ -146,6 +141,7 @@ function useDownloader(opts: DownloaderOptions): Operation<Downloader> {
});
} else {
yield* call(async () => {
let destpath = path;
let destdir = dirname(destpath);
await ensureDir(destdir);
await Deno.writeFile(destpath, response.body!);
Expand Down
Loading

0 comments on commit 9dbffbf

Please sign in to comment.