Skip to content

Commit ddcffe6

Browse files
committed
fix meta tags
1 parent 4bee484 commit ddcffe6

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

functions/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// <reference path="../node_modules/@cloudflare/workers-types/index.d.ts" />
22

3-
import { getProjectInfo } from './utils';
3+
import { encodeHTML, getProjectInfo } from './utils';
44

55
type Env = Record<'API_TOKEN', string>;
66
type Data = Record<string, unknown>;
@@ -54,15 +54,15 @@ export const onRequest: PgFunction = async function (context) {
5454
.replace(
5555
/title" content="LiveCodes"/g,
5656
`title" content="${
57-
!title || title === 'Untitled Project' ? 'LiveCodes' : title + ' - LiveCodes'
57+
!title || title === 'Untitled Project' ? 'LiveCodes' : encodeHTML(title) + ' - LiveCodes'
5858
}"`,
5959
)
6060
.replace(
6161
/content="A Code Playground That Just Works!"/g,
6262
`content="${
6363
!title && !description
6464
? 'A Code Playground That Just Works!'
65-
: description || 'A project on LiveCodes.'
65+
: encodeHTML(description || 'A project on LiveCodes.')
6666
}"`,
6767
)
6868
.replace(/content="https:\/\/livecodes.io\/"/g, `content="${request.url}"`)
@@ -83,7 +83,7 @@ export const onRequest: PgFunction = async function (context) {
8383

8484
context.waitUntil(logToAPI(context));
8585
return response;
86-
} catch (err) {
86+
} catch (err: any) {
8787
context.data = {
8888
...data,
8989
ok: false,

functions/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,11 @@ export const getProjectInfo = async (url: URL): Promise<ProjectInfo> => {
7373
description: '',
7474
};
7575
};
76+
77+
export const encodeHTML = (html: string) =>
78+
html
79+
.replace(/&/g, '&amp;')
80+
.replace(/</g, '&lt;')
81+
.replace(/>/g, '&gt;')
82+
.replace(/'/g, '&#39;')
83+
.replace(/"/g, '&#34;');

0 commit comments

Comments
 (0)