@tylix/compiler 0.5.1 → 0.5.2
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/package.json +1 -1
- package/src/renderPageDocument.js +29 -2
package/package.json
CHANGED
|
@@ -33,8 +33,7 @@ const USE_CHANNEL_SOURCE = fs
|
|
|
33
33
|
.readFileSync(path.join(__dirname, 'runtime', 'useChannel.js'), 'utf-8')
|
|
34
34
|
.replace(/export\s+/g, '')
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
const NOT_FOUND_SOURCE = fs
|
|
36
|
+
const NOT_FOUND_SOURCE = fs
|
|
38
37
|
.readFileSync(path.join(__dirname, 'runtime', 'notFound.js'), 'utf-8')
|
|
39
38
|
.replace(/export\s+/g, '')
|
|
40
39
|
|
|
@@ -89,6 +88,29 @@ async function loadCapabilityDefinitions(capabilitiesDir) {
|
|
|
89
88
|
return definitions
|
|
90
89
|
}
|
|
91
90
|
|
|
91
|
+
const headCache = new Map() // headFile -> { mtimeMs, html }
|
|
92
|
+
|
|
93
|
+
// Optional project file (app/head.html) whose contents are dropped into
|
|
94
|
+
// <head> on every page: extra <script>, <meta> or <link> tags. A missing
|
|
95
|
+
// file means no extra tags. Cached by modified time so production does not
|
|
96
|
+
// re-read it on every request, while dev edits show up on the next reload.
|
|
97
|
+
async function loadHeadTags(headFile) {
|
|
98
|
+
let stat
|
|
99
|
+
try {
|
|
100
|
+
stat = await fs.promises.stat(headFile)
|
|
101
|
+
} catch {
|
|
102
|
+
return ''
|
|
103
|
+
}
|
|
104
|
+
if (!stat.isFile()) return ''
|
|
105
|
+
|
|
106
|
+
const cached = headCache.get(headFile)
|
|
107
|
+
if (cached && cached.mtimeMs === stat.mtimeMs) return cached.html
|
|
108
|
+
|
|
109
|
+
const html = await fs.promises.readFile(headFile, 'utf-8')
|
|
110
|
+
headCache.set(headFile, { mtimeMs: stat.mtimeMs, html })
|
|
111
|
+
return html
|
|
112
|
+
}
|
|
113
|
+
|
|
92
114
|
function compileComponentSource(source, fallbackClassName) {
|
|
93
115
|
const isNativeComponent = /^\s*component\s+\w+/.test(source)
|
|
94
116
|
|
|
@@ -165,6 +187,8 @@ export async function renderPageDocument(
|
|
|
165
187
|
// working exactly as before.
|
|
166
188
|
stylesheets = ['/tailwind.css'],
|
|
167
189
|
capabilitiesDir = path.join(process.cwd(), 'app', 'capabilities'),
|
|
190
|
+
// Optional file of extra <head> tags (scripts, meta, links).
|
|
191
|
+
headFile = path.join(process.cwd(), 'app', 'head.html'),
|
|
168
192
|
} = {},
|
|
169
193
|
) {
|
|
170
194
|
const {
|
|
@@ -188,6 +212,7 @@ export async function renderPageDocument(
|
|
|
188
212
|
const { code, rootVar } = generateTemplate(templateNodes)
|
|
189
213
|
|
|
190
214
|
const capabilityDefinitions = await loadCapabilityDefinitions(capabilitiesDir)
|
|
215
|
+
const headTags = await loadHeadTags(headFile)
|
|
191
216
|
|
|
192
217
|
const childNames = Object.keys(childComponents)
|
|
193
218
|
const childClassSources = childNames
|
|
@@ -334,6 +359,7 @@ ${layoutMountCode}
|
|
|
334
359
|
<html>
|
|
335
360
|
<head>
|
|
336
361
|
<meta charset="UTF-8">
|
|
362
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
337
363
|
${channelsPortScript}
|
|
338
364
|
<script>
|
|
339
365
|
(function () {
|
|
@@ -347,6 +373,7 @@ ${layoutMountCode}
|
|
|
347
373
|
<title>${pageNode.title ?? pageName}</title>
|
|
348
374
|
<link rel="icon" type="image/png" href="/favicon.png">
|
|
349
375
|
${styleLinks}
|
|
376
|
+
${headTags}
|
|
350
377
|
${styleTag}
|
|
351
378
|
</head>
|
|
352
379
|
<body>
|