deno.land / x / lume@v2.1.4 / core / file.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import { posix } from "../deps/path.ts";import { documentToString, stringToDocument } from "./utils/dom.ts";
import type { MergeStrategy } from "./utils/merge_data.ts";import type { ProxyComponents } from "./source.ts";import type { Entry } from "./fs.ts";
/** A page of the site */export class Page<D extends Data = Data> { /** The src info */ src: Src;
/** * Used to save the page data */ data: D = {} as D;
/** * Internal data. Used to save arbitrary data by plugins and processors */ #_data = {};
/** The page content (string or Uint8Array) */ #content?: Content;
/** The parsed HTML (only for HTML documents) */ #document?: Document;
/** Convenient way to create a page dynamically */ static create(data: Partial<Data> & { url: string }): Page { let { url, ...rest } = data; const basename = posix.basename(url).replace(/\.[\w.]+$/, ""); const page = new Page();
if (url.endsWith("/index.html")) { url = url.slice(0, -10); }
page.data = { ...rest, url, page, basename } as Data; page.content = data.content as Content | undefined;
return page; }
constructor(src?: Partial<Src>) { this.src = { path: "", ext: "", asset: true, ...src }; }
/** * The property _data is to store internal data, * used by plugins, processors, etc to save arbitrary values */ set _data(data: Record<string, unknown>) { this.#_data = data; }
get _data() { return this.#_data; }
/** Duplicate this page. */ duplicate(index: number | undefined, data: D): Page<D> { const page = new Page<D>({ ...this.src });
if (index !== undefined) { page.src.path += `[${index}]`; }
data.page = page; page.data = data;
return page; }
/** Returns the output path of this page */ get outputPath(): string { const url = this.data.url; return decodeURI(url.endsWith("/") ? url + "index.html" : url); }
/** Returns the source path of this page */ get sourcePath(): string { if (this.src.entry?.flags.has("remote")) { return this.src.entry.src; }
if (!this.src.path) { return "(generated)"; }
return this.src.path + this.src.ext; }
/** The content of this page */ set content(content: Content | undefined) { this.#document = undefined; this.#content = content instanceof Uint8Array ? content : content && content.toString(); }
get content(): Content | undefined { if (this.#document) { this.#content = documentToString(this.#document); this.#document = undefined; }
return this.#content; }
/** The parsed HTML code from the content */ set document(document: Document | undefined) { this.#content = undefined; this.#document = document; }
get document(): Document | undefined { if (this.#document) { return this.#document; }
const url = this.outputPath;
if (this.#content && url.endsWith(".html")) { this.#document = stringToDocument(this.#content.toString()); }
return this.#document; }}
export interface StaticFile { /** The Entry instance of the file */ entry: Entry;
/** The final url destination */ outputPath: string;}
/** The .src property for a Page */export interface Src { /** If the page was loaded as asset or not */ asset: boolean;
/** The path to the file (without extension) */ path: string;
/** The extension of the file */ ext: string;
/** The original entry instance (empty for pages generated dynamically) */ entry?: Entry;}
/** The .content property for a Page */export type Content = Uint8Array | string;
/** The data of a page declared initially */export interface RawData { /** List of tags assigned to a page or folder */ tags?: string | string[];
/** The url of a page */ url?: string | false | ((page: Page) => string | false);
/** The basename of a page */ basename?: string;
/** Mark the page as a draft */ draft?: boolean;
/** The date creation of the page */ date?: Date | string | number;
/** To configure the rendering order of a page */ renderOrder?: number;
/** The raw content of a page */ content?: unknown;
/** The layout used to render a page */ layout?: string;
/** To configure a different template engine(s) to render a page */ templateEngine?: string | string[];
/** To configure how some data keys will be merged with the parent */ mergedKeys?: Record<string, MergeStrategy>;
/** Whether render this page on demand or not */ onDemand?: boolean;
// deno-lint-ignore no-explicit-any [index: string]: any;}
/** The data of a page/folder once loaded and processed */export interface Data extends RawData { /** The title of the page */ title?: string;
/** The type of the page (used to group pages in collections) */ type?: string;
/** The id of the page (used to identify a page in a collection) */ id?: string | number;
/** List of tags assigned to a page or folder */ tags: string[];
/** The url of a page */ url: string;
/** The basename of the page */ basename: string;
/** The date creation of the page */ date: Date;
/** * The available components * @see https://lume.land/docs/core/components/ */ comp: ProxyComponents;
/** The page reference */ page: Page;
/** The language of the page */ lang?: string;
/** * Unmatched Language URL * The url for when the user's language doesn't match with any of the site's available languages. * * Valid values are: * - External URL string (http, https), which is language selector page * - Source path string (/), which is language selector page * - Language code (en, gl, vi), which is fallback language page * * This option is made for x-default feature. * @see https://developers.google.com/search/docs/specialty/international/localized-versions#xdefault */ unmatchedLangUrl?: string;
/** * Alternate pages (for languages) * @see https://lume.land/plugins/multilanguage/ */ alternates?: Data[];}
lume

Version Info

Tagged at
7 months ago