boxwood 0.61.4 → 0.62.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +28 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { join } = require('path')
|
|
2
|
+
const { readFileSync } = require('fs')
|
|
1
3
|
const csstree = require('css-tree')
|
|
2
4
|
const toHash = require('string-hash')
|
|
3
5
|
|
|
@@ -13,12 +15,21 @@ async function compile(path) {
|
|
|
13
15
|
if (node.name === 'head') {
|
|
14
16
|
nodes.head = node
|
|
15
17
|
}
|
|
18
|
+
if (node.name === 'body') {
|
|
19
|
+
nodes.body = node
|
|
20
|
+
}
|
|
16
21
|
if (node.name === 'style') {
|
|
17
|
-
|
|
22
|
+
const css = node.children
|
|
23
|
+
if (!styles.includes(css)) {
|
|
24
|
+
styles.push(css)
|
|
25
|
+
}
|
|
18
26
|
node.ignore = true
|
|
19
27
|
}
|
|
20
28
|
if (node.name === 'script') {
|
|
21
|
-
|
|
29
|
+
const js = node.children
|
|
30
|
+
if (!scripts.includes(js)) {
|
|
31
|
+
scripts.push(js)
|
|
32
|
+
}
|
|
22
33
|
node.ignore = true
|
|
23
34
|
}
|
|
24
35
|
if (Array.isArray(node)) {
|
|
@@ -35,8 +46,10 @@ async function compile(path) {
|
|
|
35
46
|
children: styles.join(''),
|
|
36
47
|
})
|
|
37
48
|
}
|
|
49
|
+
}
|
|
50
|
+
if (nodes.body) {
|
|
38
51
|
if (scripts.length > 0) {
|
|
39
|
-
nodes.
|
|
52
|
+
nodes.body.children.push({
|
|
40
53
|
name: 'script',
|
|
41
54
|
children: scripts.join(''),
|
|
42
55
|
})
|
|
@@ -247,6 +260,12 @@ function css(inputs) {
|
|
|
247
260
|
}
|
|
248
261
|
}
|
|
249
262
|
|
|
263
|
+
css.load = function () {
|
|
264
|
+
const path = join(...arguments)
|
|
265
|
+
const content = readFileSync(path, 'utf8')
|
|
266
|
+
return css`${content}`
|
|
267
|
+
}
|
|
268
|
+
|
|
250
269
|
function js(inputs) {
|
|
251
270
|
let result = ''
|
|
252
271
|
for (let i = 0, ilen = inputs.length; i < ilen; i += 1) {
|
|
@@ -263,6 +282,12 @@ function js(inputs) {
|
|
|
263
282
|
}
|
|
264
283
|
}
|
|
265
284
|
|
|
285
|
+
js.load = function () {
|
|
286
|
+
const path = join(...arguments)
|
|
287
|
+
const content = readFileSync(path, 'utf8')
|
|
288
|
+
return js`${content}`
|
|
289
|
+
}
|
|
290
|
+
|
|
266
291
|
const node = (name) => (options, children) => tag(name, options, children)
|
|
267
292
|
const doctype = node('!DOCTYPE html')
|
|
268
293
|
|