@xylabs/sdk-meta 5.0.80 → 5.0.81
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/README.md +32 -0
- package/dist/neutral/index.mjs +1 -0
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/meta/builder.d.ts +2 -0
- package/dist/neutral/meta/builder.d.ts.map +1 -1
- package/package.json +5 -8
- package/src/html/index.ts +0 -1
- package/src/html/mergeDocumentHead.ts +0 -47
- package/src/html/spec/destination.html +0 -23
- package/src/html/spec/source.html +0 -2724
- package/src/index.ts +0 -4
- package/src/lib/getMetaAsDict.ts +0 -22
- package/src/lib/index.ts +0 -1
- package/src/meta/builder.ts +0 -53
- package/src/meta/index.ts +0 -1
- package/src/models/Meta.ts +0 -9
- package/src/models/OpenGraph/OpenGraphMeta.ts +0 -17
- package/src/models/OpenGraph/OpenGraphStructured.ts +0 -9
- package/src/models/OpenGraph/OpenGraphStructuredProperty.ts +0 -3
- package/src/models/OpenGraph/index.ts +0 -3
- package/src/models/Twitter/Twitter.ts +0 -67
- package/src/models/Twitter/TwitterApp.ts +0 -17
- package/src/models/Twitter/TwitterPlayer.ts +0 -23
- package/src/models/Twitter/index.ts +0 -3
- package/src/models/index.ts +0 -3
- package/src/spec/template.html +0 -42
package/src/index.ts
DELETED
package/src/lib/getMetaAsDict.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { isString } from '@xylabs/typeof'
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
3
|
-
export type StringIndexable = { [key: string]: any }
|
|
4
|
-
|
|
5
|
-
const propertyDelimiter = ':'
|
|
6
|
-
|
|
7
|
-
export const getMetaAsDict = (obj: StringIndexable, parentKey?: string): Record<string, string> => {
|
|
8
|
-
let flatRecord: StringIndexable = {}
|
|
9
|
-
for (const key in obj) {
|
|
10
|
-
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
11
|
-
// If the value is another object, we want to iterate through its keys as well.
|
|
12
|
-
const childRecord = getMetaAsDict(obj[key] as StringIndexable, `${isString(parentKey) ? parentKey : ''}${key}${propertyDelimiter}`)
|
|
13
|
-
flatRecord = { ...flatRecord, ...childRecord }
|
|
14
|
-
} else {
|
|
15
|
-
// Concatenate the key with its parent key.
|
|
16
|
-
const newKey = isString(parentKey) ? `${parentKey}${key}` : key
|
|
17
|
-
const trimmed = newKey.endsWith(propertyDelimiter) ? newKey.slice(0, -1) : newKey
|
|
18
|
-
flatRecord[trimmed] = `${obj[key]}`
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return flatRecord
|
|
22
|
-
}
|
package/src/lib/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './getMetaAsDict.ts'
|
package/src/meta/builder.ts
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { isString } from '@xylabs/typeof'
|
|
2
|
-
import type { CheerioAPI } from 'cheerio'
|
|
3
|
-
import { load } from 'cheerio'
|
|
4
|
-
|
|
5
|
-
import { getMetaAsDict } from '../lib/index.ts'
|
|
6
|
-
import type { Meta } from '../models/index.ts'
|
|
7
|
-
|
|
8
|
-
/* test change */
|
|
9
|
-
|
|
10
|
-
const addMetaToHead = ($: CheerioAPI, name: string, value: string | object) => {
|
|
11
|
-
if (typeof value === 'string') {
|
|
12
|
-
const newMeta = `<meta property="${name}" content="${value}" />`
|
|
13
|
-
const existingMeta = $(`head meta[property="${name}"]`)
|
|
14
|
-
if ((existingMeta?.length ?? 0) > 0) {
|
|
15
|
-
existingMeta.replaceWith(newMeta)
|
|
16
|
-
} else {
|
|
17
|
-
$('head').append(newMeta)
|
|
18
|
-
}
|
|
19
|
-
} else if (Array.isArray(value)) {
|
|
20
|
-
for (const item of value) addMetaToHead($, `${name}`, item)
|
|
21
|
-
} else if (typeof value === 'object') {
|
|
22
|
-
for (let [key, v] of Object.entries(value)) {
|
|
23
|
-
if (key === 'url') {
|
|
24
|
-
addMetaToHead($, name, v)
|
|
25
|
-
} else {
|
|
26
|
-
addMetaToHead($, `${name}:${key}`, v)
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
} else {
|
|
30
|
-
throw new TypeError(`Invalid item type [${name}, ${typeof value}]`)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export const metaBuilder = (html: string, meta: Meta, handler?: string) => {
|
|
35
|
-
const $ = load(html)
|
|
36
|
-
// NOTE: This assumes unique meta properties (no duplicates)
|
|
37
|
-
// which is generally the case, but not always (you can have
|
|
38
|
-
// multiple og:video:tag tags, for example)
|
|
39
|
-
const metaProperties = getMetaAsDict(meta)
|
|
40
|
-
for (const [key, value] of Object.entries(metaProperties)) {
|
|
41
|
-
addMetaToHead($, key, value)
|
|
42
|
-
}
|
|
43
|
-
if (isString(meta.description)) {
|
|
44
|
-
addMetaToHead($, 'description', meta.description)
|
|
45
|
-
}
|
|
46
|
-
if (isString(meta.title)) {
|
|
47
|
-
$('title').text(meta.title)
|
|
48
|
-
}
|
|
49
|
-
if (isString(handler)) {
|
|
50
|
-
addMetaToHead($, 'meta-handler', handler)
|
|
51
|
-
}
|
|
52
|
-
return $.html()
|
|
53
|
-
}
|
package/src/meta/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './builder.ts'
|
package/src/models/Meta.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { OpenGraphStructuredProperty } from './OpenGraphStructuredProperty.ts'
|
|
2
|
-
|
|
3
|
-
// TODO: There is slightly different fields for video/image/audio and we should create
|
|
4
|
-
// separate interfaces for each
|
|
5
|
-
|
|
6
|
-
export interface OpenGraphMeta {
|
|
7
|
-
audio?: OpenGraphStructuredProperty
|
|
8
|
-
description?: string
|
|
9
|
-
determiner?: string
|
|
10
|
-
image?: OpenGraphStructuredProperty
|
|
11
|
-
locale?: string | string[]
|
|
12
|
-
site_name?: string
|
|
13
|
-
title?: string
|
|
14
|
-
type?: string
|
|
15
|
-
url?: string
|
|
16
|
-
video?: OpenGraphStructuredProperty
|
|
17
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { TwitterApp } from './TwitterApp.ts'
|
|
2
|
-
import type { TwitterPlayer } from './TwitterPlayer.ts'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/markup
|
|
6
|
-
*/
|
|
7
|
-
export interface TwitterMeta {
|
|
8
|
-
app?: TwitterApp
|
|
9
|
-
/**
|
|
10
|
-
* The card type. Used with all cards. Fallback: og:type.
|
|
11
|
-
* If an og:type, og:title and og:description exist in the markup but
|
|
12
|
-
* twitter:card is absent, then a summary card may be rendered.
|
|
13
|
-
*/
|
|
14
|
-
card?: 'summary' | 'summary_large_image' | 'app' | 'player'
|
|
15
|
-
|
|
16
|
-
creator?: {
|
|
17
|
-
/**
|
|
18
|
-
* The @username of content creator. Used with summary_large_image cards
|
|
19
|
-
*/
|
|
20
|
-
''?: string
|
|
21
|
-
/**
|
|
22
|
-
* Twitter user ID of content creator. Used with summary,
|
|
23
|
-
* summary_large_image cards
|
|
24
|
-
*/
|
|
25
|
-
'id'?: string
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Description of content (maximum 200 characters). Used with summary,
|
|
29
|
-
* summary_large_image, player cards. Fallback: og:description.
|
|
30
|
-
*/
|
|
31
|
-
description?: string
|
|
32
|
-
image?: {
|
|
33
|
-
/**
|
|
34
|
-
* URL of image to use in the card. Images must be less than 5MB in size.
|
|
35
|
-
* JPG, PNG, WEBP and GIF formats are supported. Only the first frame of
|
|
36
|
-
* an animated GIF will be used. SVG is not supported. Used with summary,
|
|
37
|
-
* summary_large_image, player cards. Fallback: og:image
|
|
38
|
-
*/
|
|
39
|
-
''?: string
|
|
40
|
-
/**
|
|
41
|
-
* A text description of the image conveying the essential nature of
|
|
42
|
-
* an image to users who are visually impaired. Maximum 420
|
|
43
|
-
* characters. Used with summary, summary_large_image, player cards
|
|
44
|
-
*/
|
|
45
|
-
'alt'?: string
|
|
46
|
-
}
|
|
47
|
-
player?: TwitterPlayer
|
|
48
|
-
/**
|
|
49
|
-
* The @username of website. Either twitter:site or twitter:site:id is
|
|
50
|
-
* required. Used with summary, summary_large_image, app, player
|
|
51
|
-
* cards
|
|
52
|
-
*/
|
|
53
|
-
site?: {
|
|
54
|
-
''?: string
|
|
55
|
-
/**
|
|
56
|
-
* Same as twitter:site, but the user’s Twitter ID. Either
|
|
57
|
-
* twitter:site or twitter:site:id is required. Used with
|
|
58
|
-
* summary, summary_large_image, player cards
|
|
59
|
-
*/
|
|
60
|
-
'id'?: string
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Title of content (max 70 characters). Used with summary,
|
|
64
|
-
* summary_large_image, player cards. Fallback: og:title.
|
|
65
|
-
*/
|
|
66
|
-
title?: string
|
|
67
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface TwitterApp {
|
|
2
|
-
id?: {
|
|
3
|
-
googleplay?: string
|
|
4
|
-
ipad?: string
|
|
5
|
-
iphone?: string
|
|
6
|
-
}
|
|
7
|
-
name?: {
|
|
8
|
-
googleplay?: string
|
|
9
|
-
ipad?: string
|
|
10
|
-
iphone?: string
|
|
11
|
-
}
|
|
12
|
-
url?: {
|
|
13
|
-
googleplay?: string
|
|
14
|
-
ipad?: string
|
|
15
|
-
iphone?: string
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* https://developer.twitter.com/en/docs/twitter-for-websites/cards/overview/player-card
|
|
3
|
-
*/
|
|
4
|
-
export interface TwitterPlayer {
|
|
5
|
-
/**
|
|
6
|
-
* HTTPS URL to iFrame player. This must be a HTTPS URL which does not
|
|
7
|
-
* generate active mixed content warnings in a web browser. The audio or
|
|
8
|
-
* video player must not require plugins such as Adobe Flash.
|
|
9
|
-
*/
|
|
10
|
-
'': string
|
|
11
|
-
/**
|
|
12
|
-
* Height of iframe in pixels. Used with player card
|
|
13
|
-
*/
|
|
14
|
-
'height'?: number
|
|
15
|
-
/**
|
|
16
|
-
* URL to raw video or audio stream. Used with player card
|
|
17
|
-
*/
|
|
18
|
-
'stream'?: string
|
|
19
|
-
/**
|
|
20
|
-
* Width of iframe in pixels. Used with player card
|
|
21
|
-
*/
|
|
22
|
-
'width'?: number
|
|
23
|
-
}
|
package/src/models/index.ts
DELETED
package/src/spec/template.html
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="utf-8" />
|
|
6
|
-
<link rel="icon" href="/favicon.ico" />
|
|
7
|
-
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
8
|
-
<meta name="theme-color" content="#000000" />
|
|
9
|
-
<meta name="description" content="Own your piece of XYO's Decentralized Digital World!" />
|
|
10
|
-
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
|
11
|
-
<link rel="manifest" href="/manifest.json" />
|
|
12
|
-
<title>XYO 2.0</title>
|
|
13
|
-
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans|Lexend+Deca|Rock+Salt|Source+Code+Pro&display=swap"
|
|
14
|
-
rel="stylesheet">
|
|
15
|
-
<script async src="https://www.googletagmanager.com/gtag/js?id=G-795QBPW744"></script>
|
|
16
|
-
<script>function gtag() { dataLayer.push(arguments) } window.dataLayer = window.dataLayer || [], gtag("js", new Date), gtag("config", "G-795QBPW744")</script>
|
|
17
|
-
<style>
|
|
18
|
-
html {
|
|
19
|
-
overflow-y: auto;
|
|
20
|
-
overflow-x: hidden
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
#root,
|
|
24
|
-
body {
|
|
25
|
-
height: 100%;
|
|
26
|
-
width: 100%;
|
|
27
|
-
margin: 0;
|
|
28
|
-
padding: 0
|
|
29
|
-
}
|
|
30
|
-
</style>
|
|
31
|
-
<script defer="defer" src="/static/js/main.ae7f7033.js"></script>
|
|
32
|
-
<link href="/static/css/main.026e3fe6.css" rel="stylesheet">
|
|
33
|
-
</head>
|
|
34
|
-
|
|
35
|
-
<body style="padding:0;margin:0;overflow-x:hidden"><noscript><iframe
|
|
36
|
-
src="https://www.googletagmanager.com/ns.html?id=GTM-W2TFNXL" height="0" width="0"
|
|
37
|
-
style="display:none;visibility:hidden"></iframe></noscript><noscript>You need to enable JavaScript to run this
|
|
38
|
-
app.</noscript>
|
|
39
|
-
<div id="root"></div>
|
|
40
|
-
</body>
|
|
41
|
-
|
|
42
|
-
</html>
|