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

filter_pages.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
import { merge } from "../core/utils/object.ts";
import type Site from "../core/site.ts";import type { Extensions } from "../core/utils/path.ts";import type { Page } from "../core/file.ts";
export interface Options { /** The list of extensions this plugin applies to */ extensions?: Extensions;
/** * The function to test the page * @default `(page) => true` */ fn: (page: Page) => boolean;}
// Default optionsexport const defaults: Options = { extensions: "*", fn: () => true,};
/** A plugin to filter only some pages */export default function (userOptions: Options) { const options = merge(defaults, userOptions);
return (site: Site) => { site.process(options.extensions, (pages, allPages) => { for (const page of pages) { if (!options.fn(page)) { allPages.splice(allPages.indexOf(page), 1); } } }); };}
lume

Version Info

Tagged at
7 months ago