Skip to content

Commit 0df57e7

Browse files
committed
fix: sync system
1 parent 5402cbf commit 0df57e7

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

.github/scripts/sync-blog.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,27 @@ const PAGE_SIZE = 10;
77

88
const iframe = `<iframe src="$1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" style="width: 100%; height: 500px;" allowfullscreen></iframe>`;
99
const iframeRegex = /:::\s*@iframe\s+(.*?)\s*:::/g;
10+
11+
const replaceFrontmatter = (text) => {
12+
if (!text) return '';
13+
// First clean the text
14+
const cleaned = text
15+
.replace(/\r/g, '') // Remove carriage returns
16+
.replace(/\t/g, ' ') // Replace tabs with spaces
17+
.replace(/[^\x20-\x7E]/g, '') // Remove non-printable characters
18+
.trim(); // Remove leading/trailing whitespace
19+
20+
// If text contains any special characters, wrap it in double quotes and escape properly
21+
if (/[:'"`\n]/.test(cleaned)) {
22+
return `"${cleaned
23+
.replace(/"/g, '\\"') // Escape double quotes
24+
.replace(/\n/g, '\\n') // Escape newlines
25+
}"`;
26+
}
27+
28+
return cleaned;
29+
}
30+
1031
async function main() {
1132
if (!process.env.SEOBOT_API_KEY) {
1233
throw new Error('SEOBOT_API_KEY environment variable is required');
@@ -42,17 +63,17 @@ async function main() {
4263
const frontmatter = [
4364
'---',
4465
`slug: ${article.slug}`,
45-
`title: '${article.headline}'`,
46-
`description: '${article.metaDescription}'`,
66+
`title: ${replaceFrontmatter(article.headline)}`,
67+
`description: ${replaceFrontmatter(article.metaDescription)}`,
4768
'author: Martin Donadieu',
4869
'author_image_url: https://avatars.githubusercontent.com/u/4084527?v=4',
4970
'author_url: https://github.com/riderx',
5071
`created_at: ${article.createdAt}`,
5172
`updated_at: ${article.updatedAt}`,
5273
`head_image: ${article.image}`,
53-
`head_image_alt: '${article.category.title}'`,
54-
`keywords: '${articleResponse.metaKeywords}'`,
55-
`tag: '${article.tags.map(tag => tag.title).join(', ')}'`,
74+
`head_image_alt: ${replaceFrontmatter(article.category.title)}`,
75+
`keywords: ${replaceFrontmatter(articleResponse.metaKeywords)}`,
76+
`tag: ${replaceFrontmatter(article.tags.map(tag => tag.title).join(', '))}`,
5677
'published: true',
5778
'locale: en',
5879
'next_blog: \'\'',

0 commit comments

Comments
 (0)