deno.land / x / lume@v2.1.4 / plugins / minify_html.ts

minify_html.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { minify } from "../deps/minify_html.ts";import { merge } from "../core/utils/object.ts";
import type { Options as MinifyOptions } from "../deps/minify_html.ts";import type Site from "../core/site.ts";import type { Page } from "../core/file.ts";
export interface Options { /** The list of extensions this plugin applies to. */ extensions?: Array<".html" | ".css" | ".js">;
/** Default options for minify-html library */ options?: MinifyOptions;}
// Default optionsexport const defaults: Options = { extensions: [".html"], options: { do_not_minify_doctype: true, ensure_spec_compliant_unquoted_attribute_values: true, keep_closing_tags: false, keep_html_and_head_opening_tags: false, keep_spaces_between_attributes: false, keep_comments: false, minify_js: true, minify_css: true, remove_bangs: false, remove_processing_instructions: false, },};
/** A plugin to minify HTML, CSS & JavaScript files */export default function (userOptions?: Options) { const options = merge(defaults, userOptions);
const { extensions } = options;
// Validate supported file extensions if (extensions.some((ext) => ![".html", ".css", ".js"].includes(ext))) { throw new Error( `Unsupported extensions configuration: ${ extensions.join(", ") }. Only ".html", ".css" and ".js" are supported by minify-html plugin.`, ); }
return (site: Site) => { site.process(options.extensions, (pages) => pages.forEach(minifyHtml));
const encoder = new TextEncoder(); const decoder = new TextDecoder();
function minifyHtml(page: Page) { const content = page.content as string;
page.content = decoder.decode( minify(encoder.encode(content), options.options), ); } };}
lume

Version Info

Tagged at
5 months ago