Skip to content

Commit 1fedd53

Browse files
authored
feat: add <!DOCTYPE html> by default (#44)
1 parent 2fb3b72 commit 1fedd53

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

build_test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ Deno.test("cli.ts build <entrypoint> --dist-dir <path> -- builds the site into g
1010
);
1111
assertEquals(
1212
await Deno.readTextFile(join(tempdir, "index.html")),
13-
"<html><head></head><body><div>aaa</div>\n</body></html>",
13+
"<!DOCTYPE html><html><head></head><body><div>aaa</div>\n</body></html>",
1414
);
1515
});

generate_assets.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ type Asset = {
147147
createFileObject(params: CreateFileObjectParams): Promise<File[]>;
148148
};
149149

150+
const docType = encoder.encode("<!DOCTYPE html>");
151+
150152
/** HtmlAsset represents the html file */
151153
class HtmlAsset implements Asset {
152154
static async create(path: string): Promise<HtmlAsset> {
@@ -182,7 +184,7 @@ class HtmlAsset implements Asset {
182184

183185
createFileObject(_params: CreateFileObjectParams) {
184186
return Promise.resolve([Object.assign(
185-
new Blob([encoder.encode(this.#doc.body.parentElement!.outerHTML)]),
187+
new Blob([docType, encoder.encode(this.#doc.documentElement!.outerHTML)]),
186188
{ name: this.#filename },
187189
)]);
188190
}

serve_test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ Deno.test("cli.ts serve <entrypoint> --port <port> --livereload-port <port> -- s
1919
let res = await fetch("http://localhost:4567/index.html");
2020
assertEquals(
2121
await res.text(),
22-
`<html><head></head><body><div>aaa</div>\n<script src="http://localhost:34567/livereload.js"></script></body></html>`,
22+
`<!DOCTYPE html><html><head></head><body><div>aaa</div>\n<script src="http://localhost:34567/livereload.js"></script></body></html>`,
2323
);
2424

2525
// Non existent path returns the same response as the main html.
2626
// This is useful for apps which use client side routing.
2727
res = await fetch("http://localhost:4567/asdf");
2828
assertEquals(
2929
await res.text(),
30-
`<html><head></head><body><div>aaa</div>\n<script src="http://localhost:34567/livereload.js"></script></body></html>`,
30+
`<!DOCTYPE html><html><head></head><body><div>aaa</div>\n<script src="http://localhost:34567/livereload.js"></script></body></html>`,
3131
);
3232
p.close();
3333
});

0 commit comments

Comments
 (0)