Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions kit/postprocess.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,20 @@ function readFiles(directory) {
});
}

function processFile(filePath) {
const content = fs.readFileSync(filePath, "utf-8");

const metas = Array.from(content.matchAll(/<meta[^>]*>/g)).map((m) => m[0]);
// Regex to match `meta name="hf:doc:metadata"`
const REGEX_HF_METADATA = /<!-- HEAD_svelte-.{7}_START -->(.+)<!-- HEAD_svelte-.{7}_END -->/s;

if (metas.length) {
let newContent = content;

// Remove all meta tags from their original locations
for (const tag of metas) {
newContent = newContent.replace(tag, "");
}

// Add them back at the start of the head
newContent = newContent.replace("<!-- META HERE -->", "<!-- META HERE -->" + metas.join(""));

fs.writeFileSync(filePath, newContent);
}
function processFile(filePath) {
// Read the file synchronously
const data = fs.readFileSync(filePath, 'utf8');
// Extract the matched group using the regex
const match = data.match(REGEX_HF_METADATA);
// Append macthed group 1 to the first line
const lines = data.split('\n');
lines[0] += match[1];
// Join the lines back and write to the file synchronously
const updatedData = lines.join('\n');
fs.writeFileSync(filePath, updatedData, 'utf8');
}

readFiles(directoryPath);
2 changes: 1 addition & 1 deletion kit/src/app.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!-- META HERE --><meta charset="utf-8" />%sveltekit.head% %sveltekit.body%
<meta charset="utf-8" />%sveltekit.head% %sveltekit.body%