@verbaly/compiler 0.34.0 → 0.35.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/dist/cli.js +35 -2
- package/dist/cli.js.map +1 -1
- package/dist/index.js +35 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -2154,13 +2154,15 @@ function renderHtml(html, options) {
|
|
|
2154
2154
|
const missing = /* @__PURE__ */ new Set();
|
|
2155
2155
|
const skip = protectedRanges(html);
|
|
2156
2156
|
const inSkip = (index) => skip.some(([from, to]) => index >= from && index < to);
|
|
2157
|
+
const filled = [];
|
|
2158
|
+
const inFilled = (index) => filled.some(([from, to]) => index >= from && index < to);
|
|
2157
2159
|
const selfUrl = options.alternates?.find((a) => a.hreflang === options.locale)?.href;
|
|
2158
2160
|
const sourceUrl = options.alternates?.find((a) => a.hreflang === "x-default")?.href;
|
|
2159
2161
|
const rewriteUrl = selfUrl !== void 0 && selfUrl !== sourceUrl;
|
|
2160
2162
|
START_TAG.lastIndex = 0;
|
|
2161
2163
|
let m;
|
|
2162
2164
|
while ((m = START_TAG.exec(html)) !== null) {
|
|
2163
|
-
if (inSkip(m.index)) continue;
|
|
2165
|
+
if (inSkip(m.index) || inFilled(m.index)) continue;
|
|
2164
2166
|
const [full, rawName, attrChunk] = m;
|
|
2165
2167
|
const tagName = rawName.toLowerCase();
|
|
2166
2168
|
const openEnd = m.index + full.length;
|
|
@@ -2173,6 +2175,18 @@ function renderHtml(html, options) {
|
|
|
2173
2175
|
const attrs = parseAttrs(attrChunk);
|
|
2174
2176
|
if (rewriteUrl && tagName === "link" && attrs.get("rel")?.toLowerCase() === "canonical" && decodeEntities(attrs.get("href") ?? "") === sourceUrl) setAttribute(ms, html, chunkStart, openEnd, attrChunk, "href", selfUrl);
|
|
2175
2177
|
if (rewriteUrl && tagName === "meta" && attrs.get("property") === "og:url" && decodeEntities(attrs.get("content") ?? "") === sourceUrl) setAttribute(ms, html, chunkStart, openEnd, attrChunk, "content", selfUrl);
|
|
2178
|
+
const mirror = options.mirror;
|
|
2179
|
+
if (mirror) {
|
|
2180
|
+
if (tagName === "a" || tagName === "area") {
|
|
2181
|
+
const inside = mirroredHref(attrs.get("href"), mirror);
|
|
2182
|
+
if (inside) setAttribute(ms, html, chunkStart, openEnd, attrChunk, "href", inside);
|
|
2183
|
+
} else if (tagName === "meta" && attrs.get("http-equiv")?.toLowerCase() === "refresh") {
|
|
2184
|
+
const content = attrs.get("content") ?? "";
|
|
2185
|
+
const url = /^([^;]*;\s*url\s*=\s*)(.*)$/i.exec(decodeEntities(content));
|
|
2186
|
+
const inside = url && mirroredHref(url[2], mirror);
|
|
2187
|
+
if (inside) setAttribute(ms, html, chunkStart, openEnd, attrChunk, "content", `${url[1]}${inside}`);
|
|
2188
|
+
}
|
|
2189
|
+
}
|
|
2176
2190
|
const key = attrs.get(attr);
|
|
2177
2191
|
const attrMapRaw = attrs.get(attrsAttr);
|
|
2178
2192
|
if (key === void 0 && attrMapRaw === void 0) continue;
|
|
@@ -2191,6 +2205,7 @@ function renderHtml(html, options) {
|
|
|
2191
2205
|
const content = attrs.has(richAttr) ? richToHtml(parseTags(text), richTags, links) : escapeHtml(text);
|
|
2192
2206
|
if (html.slice(openEnd, close.contentEnd) !== content) if (openEnd === close.contentEnd) ms.appendLeft(openEnd, content);
|
|
2193
2207
|
else ms.overwrite(openEnd, close.contentEnd, content);
|
|
2208
|
+
filled.push([openEnd, close.contentEnd]);
|
|
2194
2209
|
}
|
|
2195
2210
|
}
|
|
2196
2211
|
}
|
|
@@ -2213,6 +2228,19 @@ function renderHtml(html, options) {
|
|
|
2213
2228
|
missing: [...missing]
|
|
2214
2229
|
};
|
|
2215
2230
|
}
|
|
2231
|
+
function publicPath(rel) {
|
|
2232
|
+
const path = `/${rel.replace(/(^|\/)index\.html$/, "$1")}`;
|
|
2233
|
+
return path.length > 1 ? path.replace(/\/+$/, "") : path;
|
|
2234
|
+
}
|
|
2235
|
+
function mirroredHref(raw, mirror) {
|
|
2236
|
+
if (raw === void 0) return void 0;
|
|
2237
|
+
const href = decodeEntities(raw);
|
|
2238
|
+
if (!href.startsWith("/") || href.startsWith("//")) return void 0;
|
|
2239
|
+
const cut = href.search(/[?#]/);
|
|
2240
|
+
const path = cut < 0 ? href : href.slice(0, cut);
|
|
2241
|
+
if (!mirror.pages.has(publicPath(path.replace(/^\//, "")))) return void 0;
|
|
2242
|
+
return `${mirror.prefix}${href}`;
|
|
2243
|
+
}
|
|
2216
2244
|
function injectAlternates(ms, html, alternates) {
|
|
2217
2245
|
const links = alternates.map((a) => `<link rel="alternate" hreflang="${escapeAttr(a.hreflang)}" href="${escapeAttr(a.href)}">`).join("");
|
|
2218
2246
|
const block = `${HREFLANG_OPEN}${links}${HREFLANG_CLOSE}`;
|
|
@@ -2249,6 +2277,7 @@ async function renderSite(cfg, options = {}) {
|
|
|
2249
2277
|
absolute: true,
|
|
2250
2278
|
ignore: locales.map((locale) => `${locale}/**`)
|
|
2251
2279
|
});
|
|
2280
|
+
const pages = new Set(files.map((file) => publicPath(relative(site, file).replace(/\\/g, "/"))));
|
|
2252
2281
|
const missing = {};
|
|
2253
2282
|
const urls = [];
|
|
2254
2283
|
for (const file of files) {
|
|
@@ -2267,7 +2296,11 @@ async function renderSite(cfg, options = {}) {
|
|
|
2267
2296
|
attribute,
|
|
2268
2297
|
richTags: options.richTags,
|
|
2269
2298
|
richLinks: options.richLinks ?? cfg.render.links,
|
|
2270
|
-
alternates
|
|
2299
|
+
alternates,
|
|
2300
|
+
mirror: locale === cfg.sourceLocale ? void 0 : {
|
|
2301
|
+
prefix: `/${locale}`,
|
|
2302
|
+
pages
|
|
2303
|
+
}
|
|
2271
2304
|
});
|
|
2272
2305
|
for (const key of result.missing) {
|
|
2273
2306
|
const list = missing[locale] ??= [];
|