@geekity/cms 0.56.0 → 0.57.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/admin/pages/tools/export.njk +6 -0
- package/admin/pages/tools/personal-data.njk +9 -0
- package/admin/static/admin.css +812 -1406
- package/admin/static/editor.js +26 -26
- package/dist/admin/federation.d.ts.map +1 -1
- package/dist/admin/federation.js +2 -1
- package/dist/admin/federation.js.map +1 -1
- package/dist/admin/indieauth-consent.js +1 -1
- package/dist/admin/indieauth-consent.js.map +1 -1
- package/dist/admin/personal-data.d.ts.map +1 -1
- package/dist/admin/personal-data.js +11 -2
- package/dist/admin/personal-data.js.map +1 -1
- package/dist/cli/export.d.ts.map +1 -1
- package/dist/cli/export.js +5 -1
- package/dist/cli/export.js.map +1 -1
- package/dist/cms/services.d.ts.map +1 -1
- package/dist/cms/services.js +12 -1
- package/dist/cms/services.js.map +1 -1
- package/dist/comments/conversation.d.ts +4 -3
- package/dist/comments/conversation.d.ts.map +1 -1
- package/dist/comments/intake.d.ts +19 -12
- package/dist/comments/intake.d.ts.map +1 -1
- package/dist/comments/intake.js +46 -16
- package/dist/comments/intake.js.map +1 -1
- package/dist/comments/migrations.d.ts.map +1 -1
- package/dist/comments/migrations.js +16 -2
- package/dist/comments/migrations.js.map +1 -1
- package/dist/comments/records.d.ts +24 -11
- package/dist/comments/records.d.ts.map +1 -1
- package/dist/comments/records.js +168 -63
- package/dist/comments/records.js.map +1 -1
- package/dist/config-entry.d.ts +1 -1
- package/dist/config-entry.d.ts.map +1 -1
- package/dist/config.d.ts +47 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +16 -2
- package/dist/config.js.map +1 -1
- package/dist/content/image-tags.js +2 -2
- package/dist/content/image-tags.js.map +1 -1
- package/dist/content/sanitize.d.ts.map +1 -1
- package/dist/content/sanitize.js +27 -13
- package/dist/content/sanitize.js.map +1 -1
- package/dist/content/search.d.ts.map +1 -1
- package/dist/content/search.js +1 -28
- package/dist/content/search.js.map +1 -1
- package/dist/content/sqlite/catalog.js +3 -0
- package/dist/content/sqlite/catalog.js.map +1 -1
- package/dist/content/sqlite/schema.d.ts.map +1 -1
- package/dist/content/sqlite/schema.js +13 -0
- package/dist/content/sqlite/schema.js.map +1 -1
- package/dist/content/store.d.ts +2 -0
- package/dist/content/store.d.ts.map +1 -1
- package/dist/content/store.js.map +1 -1
- package/dist/export/site-export.d.ts +1 -0
- package/dist/export/site-export.d.ts.map +1 -1
- package/dist/export/site-export.js +2 -0
- package/dist/export/site-export.js.map +1 -1
- package/dist/export/site-import.d.ts.map +1 -1
- package/dist/export/site-import.js +1 -0
- package/dist/export/site-import.js.map +1 -1
- package/dist/exports.d.ts +1 -1
- package/dist/exports.d.ts.map +1 -1
- package/dist/exports.js.map +1 -1
- package/dist/federation/federation.d.ts +3 -0
- package/dist/federation/federation.d.ts.map +1 -1
- package/dist/federation/federation.js +5 -2
- package/dist/federation/federation.js.map +1 -1
- package/dist/federation/profiles.d.ts.map +1 -1
- package/dist/federation/profiles.js +5 -1
- package/dist/federation/profiles.js.map +1 -1
- package/dist/federation/public-loaders.d.ts +14 -0
- package/dist/federation/public-loaders.d.ts.map +1 -0
- package/dist/federation/public-loaders.js +41 -0
- package/dist/federation/public-loaders.js.map +1 -0
- package/dist/files/data-files.d.ts +1 -0
- package/dist/files/data-files.d.ts.map +1 -1
- package/dist/files/data-files.js +6 -0
- package/dist/files/data-files.js.map +1 -1
- package/dist/following/list.d.ts.map +1 -1
- package/dist/following/list.js +4 -3
- package/dist/following/list.js.map +1 -1
- package/dist/forms/protection.d.ts +8 -0
- package/dist/forms/protection.d.ts.map +1 -1
- package/dist/forms/protection.js +8 -0
- package/dist/forms/protection.js.map +1 -1
- package/dist/indieauth/client.js +2 -2
- package/dist/indieauth/client.js.map +1 -1
- package/dist/mcp/endpoint.d.ts.map +1 -1
- package/dist/mcp/endpoint.js +3 -0
- package/dist/mcp/endpoint.js.map +1 -1
- package/dist/mcp/inspect/remote.js +2 -2
- package/dist/mcp/inspect/remote.js.map +1 -1
- package/dist/mcp/profile.d.ts +3 -0
- package/dist/mcp/profile.d.ts.map +1 -0
- package/dist/mcp/profile.js +143 -0
- package/dist/mcp/profile.js.map +1 -0
- package/dist/mcp/tools.d.ts +1 -1
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js.map +1 -1
- package/dist/notifications/comments.d.ts +3 -2
- package/dist/notifications/comments.d.ts.map +1 -1
- package/dist/notifications/comments.js +10 -7
- package/dist/notifications/comments.js.map +1 -1
- package/dist/privacy/erase.d.ts +6 -1
- package/dist/privacy/erase.d.ts.map +1 -1
- package/dist/privacy/erase.js +24 -9
- package/dist/privacy/erase.js.map +1 -1
- package/dist/privacy/retention.d.ts.map +1 -1
- package/dist/privacy/retention.js +7 -2
- package/dist/privacy/retention.js.map +1 -1
- package/dist/site/users.d.ts +14 -0
- package/dist/site/users.d.ts.map +1 -1
- package/dist/site/users.js +23 -1
- package/dist/site/users.js.map +1 -1
- package/dist/store/admin-store.d.ts +1 -1
- package/dist/store/admin-store.d.ts.map +1 -1
- package/dist/store/admin-store.js +1 -1
- package/dist/store/admin-store.js.map +1 -1
- package/dist/store/comments.d.ts +14 -0
- package/dist/store/comments.d.ts.map +1 -1
- package/dist/store/comments.js +40 -2
- package/dist/store/comments.js.map +1 -1
- package/dist/store/schema.d.ts.map +1 -1
- package/dist/store/schema.js +4 -0
- package/dist/store/schema.js.map +1 -1
- package/dist/util/html-entities.d.ts +5 -0
- package/dist/util/html-entities.d.ts.map +1 -0
- package/dist/util/html-entities.js +2239 -0
- package/dist/util/html-entities.js.map +1 -0
- package/dist/util/html-tree.d.ts +13 -6
- package/dist/util/html-tree.d.ts.map +1 -1
- package/dist/util/html-tree.js +171 -44
- package/dist/util/html-tree.js.map +1 -1
- package/dist/util/html.d.ts +7 -0
- package/dist/util/html.d.ts.map +1 -1
- package/dist/util/html.js +68 -19
- package/dist/util/html.js.map +1 -1
- package/dist/util/public-address.d.ts +11 -2
- package/dist/util/public-address.d.ts.map +1 -1
- package/dist/util/public-address.js +86 -13
- package/dist/util/public-address.js.map +1 -1
- package/dist/util/queue.d.ts +5 -0
- package/dist/util/queue.d.ts.map +1 -1
- package/dist/util/queue.js +18 -0
- package/dist/util/queue.js.map +1 -1
- package/dist/util/url.d.ts +11 -0
- package/dist/util/url.d.ts.map +1 -1
- package/dist/util/url.js +23 -0
- package/dist/util/url.js.map +1 -1
- package/dist/web/activity-folding.d.ts.map +1 -1
- package/dist/web/activity-folding.js +7 -3
- package/dist/web/activity-folding.js.map +1 -1
- package/dist/web/bounded-body.d.ts +12 -0
- package/dist/web/bounded-body.d.ts.map +1 -0
- package/dist/web/bounded-body.js +55 -0
- package/dist/web/bounded-body.js.map +1 -0
- package/dist/web/comment-routes.d.ts.map +1 -1
- package/dist/web/comment-routes.js +8 -2
- package/dist/web/comment-routes.js.map +1 -1
- package/dist/web/contact-routes.d.ts.map +1 -1
- package/dist/web/contact-routes.js +7 -1
- package/dist/web/contact-routes.js.map +1 -1
- package/dist/web/conversation.d.ts.map +1 -1
- package/dist/web/conversation.js +15 -7
- package/dist/web/conversation.js.map +1 -1
- package/dist/web/pingback-routes.d.ts +2 -1
- package/dist/web/pingback-routes.d.ts.map +1 -1
- package/dist/web/pingback-routes.js +59 -34
- package/dist/web/pingback-routes.js.map +1 -1
- package/dist/web/request.d.ts +0 -5
- package/dist/web/request.d.ts.map +1 -1
- package/dist/web/request.js +2 -13
- package/dist/web/request.js.map +1 -1
- package/dist/web/routes.d.ts.map +1 -1
- package/dist/web/routes.js +5 -3
- package/dist/web/routes.js.map +1 -1
- package/dist/web/site-view.d.ts +15 -0
- package/dist/web/site-view.d.ts.map +1 -1
- package/dist/web/site-view.js +1 -1
- package/dist/web/site-view.js.map +1 -1
- package/dist/web/social-profile.d.ts.map +1 -1
- package/dist/web/social-profile.js +3 -3
- package/dist/web/social-profile.js.map +1 -1
- package/dist/web/throttle.d.ts +6 -0
- package/dist/web/throttle.d.ts.map +1 -1
- package/dist/web/throttle.js +1 -1
- package/dist/web/throttle.js.map +1 -1
- package/dist/web/webmention-routes.d.ts +14 -2
- package/dist/web/webmention-routes.d.ts.map +1 -1
- package/dist/web/webmention-routes.js +65 -19
- package/dist/web/webmention-routes.js.map +1 -1
- package/dist/webmention/checks.d.ts +43 -0
- package/dist/webmention/checks.d.ts.map +1 -0
- package/dist/webmention/checks.js +103 -0
- package/dist/webmention/checks.js.map +1 -0
- package/dist/webmention/discovery.js +2 -2
- package/dist/webmention/discovery.js.map +1 -1
- package/dist/webmention/endpoint.d.ts +2 -0
- package/dist/webmention/endpoint.d.ts.map +1 -1
- package/dist/webmention/endpoint.js +2 -0
- package/dist/webmention/endpoint.js.map +1 -1
- package/dist/webmention/fetch-public.d.ts +5 -0
- package/dist/webmention/fetch-public.d.ts.map +1 -1
- package/dist/webmention/fetch-public.js +19 -1
- package/dist/webmention/fetch-public.js.map +1 -1
- package/dist/webmention/index.d.ts +2 -1
- package/dist/webmention/index.d.ts.map +1 -1
- package/dist/webmention/index.js.map +1 -1
- package/dist/webmention/links.d.ts.map +1 -1
- package/dist/webmention/links.js +4 -11
- package/dist/webmention/links.js.map +1 -1
- package/dist/webmention/microformats.d.ts +32 -9
- package/dist/webmention/microformats.d.ts.map +1 -1
- package/dist/webmention/microformats.js +341 -110
- package/dist/webmention/microformats.js.map +1 -1
- package/dist/webmention/pingback.d.ts +7 -0
- package/dist/webmention/pingback.d.ts.map +1 -1
- package/dist/webmention/pingback.js +108 -34
- package/dist/webmention/pingback.js.map +1 -1
- package/dist/webmention/receive.d.ts +28 -21
- package/dist/webmention/receive.d.ts.map +1 -1
- package/dist/webmention/receive.js +286 -65
- package/dist/webmention/receive.js.map +1 -1
- package/dist/webmention/reply-context/feed.js +2 -2
- package/dist/webmention/reply-context/feed.js.map +1 -1
- package/dist/webmention/reply-context/page.js +2 -2
- package/dist/webmention/reply-context/page.js.map +1 -1
- package/dist/webmention/service.d.ts +51 -12
- package/dist/webmention/service.d.ts.map +1 -1
- package/dist/webmention/service.js +202 -38
- package/dist/webmention/service.js.map +1 -1
- package/dist/webmention/syndication.d.ts +2 -0
- package/dist/webmention/syndication.d.ts.map +1 -1
- package/dist/webmention/syndication.js +57 -20
- package/dist/webmention/syndication.js.map +1 -1
- package/package.json +5 -5
- package/themes/default/mail/comment-digest.txt.njk +1 -1
- package/themes/default/mail/comment-pending.html.njk +20 -0
- package/themes/default/mail/comment-pending.txt.njk +31 -4
- package/themes/default/mail/comment-reply.txt.njk +1 -1
- package/themes/default/mail/contact-message.txt.njk +4 -2
- package/themes/default/mail/password-changed.txt.njk +1 -1
- package/themes/default/mail/password-reset.txt.njk +1 -1
- package/themes/default/mail/test.txt.njk +1 -1
|
@@ -12,7 +12,24 @@ const KIND_PROPERTIES = {
|
|
|
12
12
|
* page is as long as they like, and a thread is rarely more than a few deep.
|
|
13
13
|
*/
|
|
14
14
|
const NESTED_DEPTH = 8;
|
|
15
|
-
const NESTED_LIMIT =
|
|
15
|
+
const NESTED_LIMIT = 20;
|
|
16
|
+
/**
|
|
17
|
+
* How many microformats are read off one page, nested ones counted. A blog's
|
|
18
|
+
* front page carries a few hundred at most; anything past this is passed over.
|
|
19
|
+
*/
|
|
20
|
+
export const MICROFORMAT_ITEMS_PER_PAGE = 1_000;
|
|
21
|
+
/**
|
|
22
|
+
* How many characters of one value's text, or of its markup, are kept. A reply
|
|
23
|
+
* is a few paragraphs; a page that sends more is cut short here.
|
|
24
|
+
*/
|
|
25
|
+
export const MICROFORMAT_VALUE_LENGTH = 65_536;
|
|
26
|
+
/**
|
|
27
|
+
* How many of an entry's `in-reply-to` values are kept. A reply answers one
|
|
28
|
+
* thing, or a few; each one kept is looked for in the post's conversation.
|
|
29
|
+
*/
|
|
30
|
+
const IN_REPLY_TO_PER_ENTRY = 8;
|
|
31
|
+
/** How many property classes are read off one element. */
|
|
32
|
+
const PROPERTIES_PER_ELEMENT = 16;
|
|
16
33
|
/** The attributes that make an element a link to somewhere. */
|
|
17
34
|
const LINK_ATTRIBUTES = ['href', 'src', 'data', 'poster', 'cite'];
|
|
18
35
|
/**
|
|
@@ -22,16 +39,22 @@ const LINK_ATTRIBUTES = ['href', 'src', 'data', 'poster', 'cite'];
|
|
|
22
39
|
* text: a page that merely writes the target's address out is not talking to
|
|
23
40
|
* it, and one that links to it in an `<img>`, a `<video>` or a `<link>` is.
|
|
24
41
|
* The comparison is on the whole URL after both sides are resolved and
|
|
25
|
-
* normalised, so a link written relative
|
|
26
|
-
* on the same site does not.
|
|
42
|
+
* normalised, less any fragment, so a link written relative or to an anchor on
|
|
43
|
+
* the page counts and a link to a different page on the same site does not.
|
|
27
44
|
*/
|
|
28
|
-
export function linksTo(
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const wanted = normalize(target, target);
|
|
32
|
-
if (wanted === undefined)
|
|
45
|
+
export function linksTo(page, target) {
|
|
46
|
+
const resolved = normalize(target, target);
|
|
47
|
+
if (resolved === undefined)
|
|
33
48
|
return false;
|
|
34
|
-
return linkedFrom(root, base).has(
|
|
49
|
+
return linkedFrom(page.root, page.base).has(withoutFragment(resolved));
|
|
50
|
+
}
|
|
51
|
+
/** Every URL a source page links to, resolved and normalised as {@link linksTo} reads them. */
|
|
52
|
+
export function linksIn(page) {
|
|
53
|
+
return linkedFrom(page.root, page.base);
|
|
54
|
+
}
|
|
55
|
+
export function readSourcePage(html, sourceUrl) {
|
|
56
|
+
const root = parseHtml(html);
|
|
57
|
+
return { root, url: sourceUrl, base: baseOf(root, sourceUrl) };
|
|
35
58
|
}
|
|
36
59
|
/** Every URL an element and everything under it links to, normalised. */
|
|
37
60
|
function linkedFrom(root, base) {
|
|
@@ -43,7 +66,7 @@ function linkedFrom(root, base) {
|
|
|
43
66
|
continue;
|
|
44
67
|
const resolved = normalize(value, base);
|
|
45
68
|
if (resolved !== undefined)
|
|
46
|
-
found.add(resolved);
|
|
69
|
+
found.add(withoutFragment(resolved));
|
|
47
70
|
}
|
|
48
71
|
}
|
|
49
72
|
return found;
|
|
@@ -51,22 +74,23 @@ function linkedFrom(root, base) {
|
|
|
51
74
|
/**
|
|
52
75
|
* What a source page is, read out of its microformats.
|
|
53
76
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
77
|
+
* `isTarget` says whether a URL is the page being mentioned, which may answer
|
|
78
|
+
* to more than one URL. The entry chosen is the one that is actually about
|
|
79
|
+
* it: the first `h-entry` whose `in-reply-to`, `like-of` or `repost-of` names
|
|
80
|
+
* it, else the first that links to it at all, else the first on the page. A
|
|
81
|
+
* page with no `h-entry` is still a mention — plenty of pages have no
|
|
82
|
+
* microformats and still link — and it is described from its `<title>` and
|
|
83
|
+
* its host.
|
|
59
84
|
*/
|
|
60
|
-
export function sourceEntry(
|
|
61
|
-
const root =
|
|
62
|
-
const base = baseOf(root, sourceUrl);
|
|
85
|
+
export function sourceEntry(page, isTarget, now) {
|
|
86
|
+
const { root, base, url: sourceUrl } = page;
|
|
63
87
|
const items = itemsIn(root, base);
|
|
64
88
|
const entries = itemsOfType(items, 'h-entry');
|
|
65
|
-
const
|
|
66
|
-
const chosen = chooseEntry(entries,
|
|
67
|
-
const author = authorOf(chosen, items, sourceUrl);
|
|
89
|
+
const named = (url) => isTarget(withoutFragment(url));
|
|
90
|
+
const chosen = chooseEntry(root, entries, named, base);
|
|
91
|
+
const author = authorOf(chosen, items, root, sourceUrl, base);
|
|
68
92
|
const content = contentOf(chosen, root);
|
|
69
|
-
const kind = chosen === undefined ? 'mention' : kindOf(chosen,
|
|
93
|
+
const kind = chosen === undefined ? 'mention' : kindOf(chosen, named);
|
|
70
94
|
const url = (chosen === undefined ? undefined : first(chosen, 'url')?.text) ?? sourceUrl;
|
|
71
95
|
const rsvp = chosen === undefined || kind !== 'reply' ? undefined : rsvpValue(first(chosen, 'rsvp')?.text);
|
|
72
96
|
return {
|
|
@@ -74,16 +98,18 @@ export function sourceEntry(html, sourceUrl, target) {
|
|
|
74
98
|
...(rsvp === undefined ? {} : { rsvp }),
|
|
75
99
|
author,
|
|
76
100
|
content,
|
|
77
|
-
published: chosen === undefined ? null : instantOf(first(chosen, 'published')),
|
|
101
|
+
published: chosen === undefined ? null : instantOf(first(chosen, 'published'), now),
|
|
78
102
|
url,
|
|
79
|
-
replies: chosen === undefined ? [] : nestedReplies(chosen, url, sourceUrl),
|
|
103
|
+
replies: chosen === undefined ? [] : nestedReplies(chosen, url, sourceUrl, now),
|
|
80
104
|
inReplyTo: chosen === undefined
|
|
81
105
|
? []
|
|
82
106
|
: (chosen.properties['in-reply-to'] ?? [])
|
|
83
107
|
.map((value) => value.item === undefined
|
|
84
108
|
? value.text
|
|
85
109
|
: (first(value.item, 'url')?.text ?? value.text))
|
|
86
|
-
.filter((url) => url !== '')
|
|
110
|
+
.filter((url) => url !== '')
|
|
111
|
+
.filter((url, index, urls) => urls.indexOf(url) === index)
|
|
112
|
+
.slice(0, IN_REPLY_TO_PER_ENTRY),
|
|
87
113
|
};
|
|
88
114
|
}
|
|
89
115
|
/**
|
|
@@ -92,8 +118,9 @@ export function sourceEntry(html, sourceUrl, target) {
|
|
|
92
118
|
* way in turn. A reply is known by its page, so one with no `u-url`, or one
|
|
93
119
|
* already read on this page, is passed over.
|
|
94
120
|
*/
|
|
95
|
-
function nestedReplies(entry, url, sourceUrl) {
|
|
121
|
+
function nestedReplies(entry, url, sourceUrl, now) {
|
|
96
122
|
const seen = new Set([url, sourceUrl]);
|
|
123
|
+
let replied = 0;
|
|
97
124
|
const read = (item, itsUrl, depth) => {
|
|
98
125
|
if (depth >= NESTED_DEPTH)
|
|
99
126
|
return [];
|
|
@@ -106,8 +133,9 @@ function nestedReplies(entry, url, sourceUrl) {
|
|
|
106
133
|
const replies = [];
|
|
107
134
|
for (const reply of carried) {
|
|
108
135
|
const at = first(reply, 'url')?.text;
|
|
109
|
-
if (at === undefined || !isWebUrl(at) || seen.has(at) ||
|
|
136
|
+
if (at === undefined || !isWebUrl(at) || seen.has(at) || replied >= NESTED_LIMIT)
|
|
110
137
|
continue;
|
|
138
|
+
replied += 1;
|
|
111
139
|
seen.add(at);
|
|
112
140
|
const author = first(reply, 'author');
|
|
113
141
|
replies.push({
|
|
@@ -116,7 +144,7 @@ function nestedReplies(entry, url, sourceUrl) {
|
|
|
116
144
|
? cardOf(author.item)
|
|
117
145
|
: { name: author?.text ?? '', url: null, photo: null },
|
|
118
146
|
content: nestedContent(reply),
|
|
119
|
-
published: instantOf(first(reply, 'published')),
|
|
147
|
+
published: instantOf(first(reply, 'published'), now),
|
|
120
148
|
replies: read(reply, at, depth + 1),
|
|
121
149
|
});
|
|
122
150
|
}
|
|
@@ -183,30 +211,67 @@ function valuesOf(item, property) {
|
|
|
183
211
|
return (item.properties[property] ?? []).map((value) => value.text).filter((text) => text !== '');
|
|
184
212
|
}
|
|
185
213
|
/** The entry a webmention is about, or `undefined` when the page has none. */
|
|
186
|
-
function chooseEntry(entries,
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
214
|
+
function chooseEntry(root, entries, isTarget, base) {
|
|
215
|
+
for (const entry of entries) {
|
|
216
|
+
if (kindOf(entry, isTarget) !== 'mention')
|
|
217
|
+
return entry;
|
|
218
|
+
}
|
|
219
|
+
const linking = entriesLinkingTo(root, entries, isTarget, base);
|
|
220
|
+
return entries.find((entry) => linking.has(entry.element)) ?? entries[0];
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* The elements of those entries that have a link to the target somewhere
|
|
224
|
+
* inside them, found in one walk of the page however deeply they nest.
|
|
225
|
+
*/
|
|
226
|
+
function entriesLinkingTo(root, entries, isTarget, base) {
|
|
227
|
+
const isEntry = new Set(entries.map((entry) => entry.element));
|
|
228
|
+
const linking = new Set();
|
|
229
|
+
const open = [];
|
|
230
|
+
const pending = [{ element: root, leaving: false }];
|
|
231
|
+
for (let next = pending.pop(); next !== undefined; next = pending.pop()) {
|
|
232
|
+
const { element, leaving } = next;
|
|
233
|
+
if (leaving) {
|
|
234
|
+
open.pop();
|
|
235
|
+
continue;
|
|
191
236
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
237
|
+
if (element !== root && linksToTarget(element, isTarget, base)) {
|
|
238
|
+
for (let index = open.length - 1; index >= 0; index -= 1) {
|
|
239
|
+
const enclosing = open[index];
|
|
240
|
+
if (linking.has(enclosing))
|
|
241
|
+
break;
|
|
242
|
+
linking.add(enclosing);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (isEntry.has(element)) {
|
|
246
|
+
open.push(element);
|
|
247
|
+
pending.push({ element, leaving: true });
|
|
248
|
+
}
|
|
249
|
+
for (let index = element.children.length - 1; index >= 0; index -= 1) {
|
|
250
|
+
const child = element.children[index];
|
|
251
|
+
if (child !== undefined && isElement(child))
|
|
252
|
+
pending.push({ element: child, leaving: false });
|
|
195
253
|
}
|
|
196
254
|
}
|
|
197
|
-
return
|
|
255
|
+
return linking;
|
|
256
|
+
}
|
|
257
|
+
/** Whether one element, itself and not what is inside it, links to the target. */
|
|
258
|
+
function linksToTarget(element, isTarget, base) {
|
|
259
|
+
return LINK_ATTRIBUTES.some((attribute) => {
|
|
260
|
+
const value = element.attributes[attribute];
|
|
261
|
+
const resolved = value === undefined ? undefined : normalize(value, base);
|
|
262
|
+
return resolved !== undefined && isTarget(resolved);
|
|
263
|
+
});
|
|
198
264
|
}
|
|
199
265
|
/** Which of the four an entry is, given what the target is. */
|
|
200
|
-
function kindOf(entry,
|
|
201
|
-
if (target === undefined)
|
|
202
|
-
return 'mention';
|
|
266
|
+
function kindOf(entry, isTarget) {
|
|
203
267
|
for (const [property, kind] of Object.entries(KIND_PROPERTIES)) {
|
|
204
268
|
for (const value of entry.properties[property] ?? []) {
|
|
205
|
-
if (value.text
|
|
269
|
+
if (isTarget(value.text))
|
|
206
270
|
return kind;
|
|
207
271
|
// A property written as a nested `h-cite` names the target with its own
|
|
208
272
|
// `url` rather than with the value the property carries.
|
|
209
|
-
|
|
273
|
+
const cited = value.item === undefined ? undefined : first(value.item, 'url')?.text;
|
|
274
|
+
if (cited !== undefined && isTarget(cited))
|
|
210
275
|
return kind;
|
|
211
276
|
}
|
|
212
277
|
}
|
|
@@ -215,18 +280,32 @@ function kindOf(entry, target) {
|
|
|
215
280
|
/**
|
|
216
281
|
* Who wrote an entry.
|
|
217
282
|
*
|
|
218
|
-
* The entry's own `p-author` first, then
|
|
219
|
-
* then the
|
|
220
|
-
*
|
|
283
|
+
* The entry's own `p-author` first, then the `p-author` of the `h-feed` that
|
|
284
|
+
* holds it, then the page's representative `h-card`, then the source's host —
|
|
285
|
+
* which is not a name but is the truest thing the site knows, and is better on
|
|
286
|
+
* a page than an empty byline.
|
|
221
287
|
*/
|
|
222
|
-
function authorOf(entry, items, sourceUrl) {
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
288
|
+
function authorOf(entry, items, root, sourceUrl, base) {
|
|
289
|
+
const feed = entry === undefined
|
|
290
|
+
? undefined
|
|
291
|
+
: items.find((item) => item.types.includes('h-feed') && item.children.includes(entry));
|
|
292
|
+
for (const holder of [entry, feed]) {
|
|
293
|
+
const named = holder === undefined ? undefined : first(holder, 'author');
|
|
294
|
+
if (named?.item !== undefined)
|
|
295
|
+
return cardOf(named.item);
|
|
296
|
+
if (named !== undefined && isWebUrl(named.text)) {
|
|
297
|
+
const label = named.label ?? '';
|
|
298
|
+
return {
|
|
299
|
+
name: label === '' || isWebUrl(label) ? hostOf(named.text) : label,
|
|
300
|
+
url: named.text,
|
|
301
|
+
photo: null,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
if (named !== undefined && named.text !== '') {
|
|
305
|
+
return { name: named.text, url: null, photo: null };
|
|
306
|
+
}
|
|
228
307
|
}
|
|
229
|
-
const card =
|
|
308
|
+
const card = representativeCard(items, root, sourceUrl, base);
|
|
230
309
|
if (card !== undefined) {
|
|
231
310
|
const read = cardOf(card);
|
|
232
311
|
if (read.name !== '')
|
|
@@ -234,6 +313,32 @@ function authorOf(entry, items, sourceUrl) {
|
|
|
234
313
|
}
|
|
235
314
|
return { name: hostOf(sourceUrl), url: null, photo: null };
|
|
236
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* The `h-card` that stands for the page's owner: one at the top of the page,
|
|
318
|
+
* not inside an entry or a citation, whose `u-url` is the page itself or a
|
|
319
|
+
* page it links `rel=me`.
|
|
320
|
+
*/
|
|
321
|
+
function representativeCard(items, root, sourceUrl, base) {
|
|
322
|
+
const page = normalize(sourceUrl, sourceUrl);
|
|
323
|
+
const me = relMeOf(root, base);
|
|
324
|
+
return items.find((item) => item.types.includes('h-card') &&
|
|
325
|
+
(item.properties['url'] ?? []).some((url) => url.text === page || me.has(url.text)));
|
|
326
|
+
}
|
|
327
|
+
/** The pages a page links `rel=me`, resolved. */
|
|
328
|
+
function relMeOf(root, base) {
|
|
329
|
+
const me = new Set();
|
|
330
|
+
for (const element of elementsIn(root)) {
|
|
331
|
+
if (element.name !== 'a' && element.name !== 'link' && element.name !== 'area')
|
|
332
|
+
continue;
|
|
333
|
+
const rels = (element.attributes['rel'] ?? '').toLowerCase().split(/\s+/);
|
|
334
|
+
if (!rels.includes('me'))
|
|
335
|
+
continue;
|
|
336
|
+
const href = normalize(element.attributes['href'] ?? '', base);
|
|
337
|
+
if (href !== undefined)
|
|
338
|
+
me.add(href);
|
|
339
|
+
}
|
|
340
|
+
return me;
|
|
341
|
+
}
|
|
237
342
|
/** One `h-card` as a name, a page and an avatar. */
|
|
238
343
|
function cardOf(card) {
|
|
239
344
|
return {
|
|
@@ -261,12 +366,48 @@ function titleOf(root) {
|
|
|
261
366
|
}
|
|
262
367
|
return '';
|
|
263
368
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
369
|
+
const DATETIME = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?(Z|[+-]\d{2}:?\d{2})?)?$/i;
|
|
370
|
+
const EARLIEST_PUBLISHED = Date.UTC(1990, 0, 1);
|
|
371
|
+
const PUBLISHED_CLOCK_SKEW_MS = 24 * 60 * 60 * 1000;
|
|
372
|
+
/**
|
|
373
|
+
* A `dt-published` as an ISO instant, or `null` when it is not a date, is
|
|
374
|
+
* older than the web, or is more than a day after `now`. A time with no
|
|
375
|
+
* offset is UTC.
|
|
376
|
+
*/
|
|
377
|
+
function instantOf(value, now) {
|
|
378
|
+
const match = DATETIME.exec(value?.text.trim() ?? '');
|
|
379
|
+
if (match === null)
|
|
380
|
+
return null;
|
|
381
|
+
const [, year = '', month = '', day = '', hour = '0', minute = '0', second = '0', fraction = '', zone,] = match;
|
|
382
|
+
const y = Number(year);
|
|
383
|
+
const mo = Number(month) - 1;
|
|
384
|
+
const d = Number(day);
|
|
385
|
+
const h = Number(hour);
|
|
386
|
+
const mi = Number(minute);
|
|
387
|
+
const s = Number(second);
|
|
388
|
+
const local = Date.UTC(y, mo, d, h, mi, s, Number(fraction.padEnd(3, '0').slice(0, 3)));
|
|
389
|
+
const date = new Date(local);
|
|
390
|
+
const sameDay = date.getUTCFullYear() === y && date.getUTCMonth() === mo && date.getUTCDate() === d;
|
|
391
|
+
if (!sameDay || h > 23 || mi > 59 || s > 59)
|
|
392
|
+
return null;
|
|
393
|
+
const offset = offsetMinutes(zone);
|
|
394
|
+
if (offset === null)
|
|
395
|
+
return null;
|
|
396
|
+
const at = local - offset * 60 * 1000;
|
|
397
|
+
if (at < EARLIEST_PUBLISHED)
|
|
398
|
+
return null;
|
|
399
|
+
if (now !== undefined && at > now.getTime() + PUBLISHED_CLOCK_SKEW_MS)
|
|
400
|
+
return null;
|
|
401
|
+
return new Date(at).toISOString();
|
|
402
|
+
}
|
|
403
|
+
function offsetMinutes(zone) {
|
|
404
|
+
if (zone === undefined || zone.toUpperCase() === 'Z')
|
|
405
|
+
return 0;
|
|
406
|
+
const hours = Number(zone.slice(1, 3));
|
|
407
|
+
const minutes = Number(zone.slice(-2));
|
|
408
|
+
if (hours > 23 || minutes > 59)
|
|
267
409
|
return null;
|
|
268
|
-
|
|
269
|
-
return Number.isNaN(at.getTime()) ? null : at.toISOString();
|
|
410
|
+
return (zone.startsWith('-') ? -1 : 1) * (hours * 60 + minutes);
|
|
270
411
|
}
|
|
271
412
|
/** The host a source is on, for a page that never says who wrote it. */
|
|
272
413
|
function hostOf(sourceUrl) {
|
|
@@ -281,18 +422,26 @@ function hostOf(sourceUrl) {
|
|
|
281
422
|
function first(item, property) {
|
|
282
423
|
return item.properties[property]?.[0];
|
|
283
424
|
}
|
|
284
|
-
/**
|
|
425
|
+
/**
|
|
426
|
+
* Every item of one type, at any depth, in document order. One nested item can
|
|
427
|
+
* be the value of several properties at once, and it is listed once.
|
|
428
|
+
*/
|
|
285
429
|
function itemsOfType(items, type) {
|
|
286
430
|
const found = [];
|
|
287
|
-
|
|
431
|
+
const seen = new Set();
|
|
432
|
+
const pending = [...items].reverse();
|
|
433
|
+
for (let item = pending.pop(); item !== undefined; item = pending.pop()) {
|
|
434
|
+
if (seen.has(item))
|
|
435
|
+
continue;
|
|
436
|
+
seen.add(item);
|
|
288
437
|
if (item.types.includes(type))
|
|
289
438
|
found.push(item);
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
439
|
+
const inside = [
|
|
440
|
+
...item.children,
|
|
441
|
+
...Object.values(item.properties).flatMap((values) => values.flatMap((value) => (value.item === undefined ? [] : [value.item]))),
|
|
442
|
+
];
|
|
443
|
+
for (let index = inside.length - 1; index >= 0; index -= 1) {
|
|
444
|
+
pending.push(inside[index]);
|
|
296
445
|
}
|
|
297
446
|
}
|
|
298
447
|
return found;
|
|
@@ -300,14 +449,19 @@ function itemsOfType(items, type) {
|
|
|
300
449
|
/** The microformats at the top of a page: roots that are inside no other root. */
|
|
301
450
|
export function itemsIn(root, base) {
|
|
302
451
|
const items = [];
|
|
452
|
+
const reading = {
|
|
453
|
+
left: MICROFORMAT_ITEMS_PER_PAGE,
|
|
454
|
+
texts: new Map(),
|
|
455
|
+
markup: new Map(),
|
|
456
|
+
};
|
|
303
457
|
const walk = (element) => {
|
|
304
458
|
for (const child of element.children) {
|
|
305
459
|
if (!isElement(child))
|
|
306
460
|
continue;
|
|
307
|
-
if (rootTypesOf(child).length
|
|
308
|
-
items.push(parseItem(child, base));
|
|
309
|
-
else
|
|
461
|
+
if (rootTypesOf(child).length === 0)
|
|
310
462
|
walk(child);
|
|
463
|
+
else if (reading.left > 0)
|
|
464
|
+
items.push(parseItem(child, base, reading));
|
|
311
465
|
}
|
|
312
466
|
};
|
|
313
467
|
walk(root);
|
|
@@ -317,16 +471,42 @@ export function itemsIn(root, base) {
|
|
|
317
471
|
function rootTypesOf(element) {
|
|
318
472
|
return classesOf(element).filter((name) => name.startsWith('h-') && name.length > 2);
|
|
319
473
|
}
|
|
320
|
-
/**
|
|
474
|
+
/**
|
|
475
|
+
* The property classes an element carries, as `{prefix, name}` pairs, each
|
|
476
|
+
* once and no more than {@link PROPERTIES_PER_ELEMENT} of them.
|
|
477
|
+
*/
|
|
321
478
|
function propertiesOf(element) {
|
|
322
479
|
const found = [];
|
|
480
|
+
const seen = new Set();
|
|
323
481
|
for (const value of classesOf(element)) {
|
|
482
|
+
if (found.length >= PROPERTIES_PER_ELEMENT)
|
|
483
|
+
break;
|
|
324
484
|
const match = /^(p|u|e|dt)-(.+)$/.exec(value);
|
|
325
|
-
if (match
|
|
326
|
-
|
|
485
|
+
if (match === null || seen.has(value))
|
|
486
|
+
continue;
|
|
487
|
+
seen.add(value);
|
|
488
|
+
found.push({ prefix: match[1] ?? '', name: match[2] ?? '' });
|
|
327
489
|
}
|
|
328
490
|
return found;
|
|
329
491
|
}
|
|
492
|
+
/** An element's text, read once per page and no longer than a value is kept. */
|
|
493
|
+
function textIn(element, reading) {
|
|
494
|
+
let text = reading.texts.get(element);
|
|
495
|
+
if (text === undefined) {
|
|
496
|
+
text = textOf(element, MICROFORMAT_VALUE_LENGTH);
|
|
497
|
+
reading.texts.set(element, text);
|
|
498
|
+
}
|
|
499
|
+
return text;
|
|
500
|
+
}
|
|
501
|
+
/** An element's inner markup, read once per page and no longer than a value is kept. */
|
|
502
|
+
function markupIn(element, base, reading) {
|
|
503
|
+
let markup = reading.markup.get(element);
|
|
504
|
+
if (markup === undefined) {
|
|
505
|
+
markup = innerHtmlOf(element, MICROFORMAT_VALUE_LENGTH, base);
|
|
506
|
+
reading.markup.set(element, markup);
|
|
507
|
+
}
|
|
508
|
+
return markup;
|
|
509
|
+
}
|
|
330
510
|
/**
|
|
331
511
|
* One microformat, with the properties written inside it.
|
|
332
512
|
*
|
|
@@ -335,14 +515,20 @@ function propertiesOf(element) {
|
|
|
335
515
|
* entry's. That one rule is what keeps an author's name out of the entry's
|
|
336
516
|
* title.
|
|
337
517
|
*/
|
|
338
|
-
function parseItem(element, base) {
|
|
339
|
-
|
|
518
|
+
function parseItem(element, base, reading) {
|
|
519
|
+
reading.left -= 1;
|
|
520
|
+
const found = new Map();
|
|
340
521
|
const children = [];
|
|
341
522
|
// Whether anything inside is a `p-` or `e-` property or a microformat of its
|
|
342
523
|
// own, which is when mf2 stops implying a name from the whole text.
|
|
343
524
|
let textual = false;
|
|
525
|
+
let explicitUrl = false;
|
|
344
526
|
const add = (name, value) => {
|
|
345
|
-
|
|
527
|
+
const values = found.get(name);
|
|
528
|
+
if (values === undefined)
|
|
529
|
+
found.set(name, [value]);
|
|
530
|
+
else
|
|
531
|
+
values.push(value);
|
|
346
532
|
};
|
|
347
533
|
const walk = (parent) => {
|
|
348
534
|
for (const child of parent.children) {
|
|
@@ -352,12 +538,16 @@ function parseItem(element, base) {
|
|
|
352
538
|
const named = propertiesOf(child);
|
|
353
539
|
if (roots.length > 0) {
|
|
354
540
|
textual = true;
|
|
355
|
-
|
|
541
|
+
if (reading.left <= 0)
|
|
542
|
+
continue;
|
|
543
|
+
const nested = parseItem(child, base, reading);
|
|
356
544
|
if (named.length === 0)
|
|
357
545
|
children.push(nested);
|
|
358
546
|
else {
|
|
359
547
|
for (const { prefix, name } of named) {
|
|
360
|
-
|
|
548
|
+
if (prefix === 'u')
|
|
549
|
+
explicitUrl = true;
|
|
550
|
+
add(name, { text: nestedText(prefix, nested, child, base, reading), item: nested });
|
|
361
551
|
}
|
|
362
552
|
}
|
|
363
553
|
continue;
|
|
@@ -365,23 +555,26 @@ function parseItem(element, base) {
|
|
|
365
555
|
for (const { prefix, name } of named) {
|
|
366
556
|
if (prefix === 'p' || prefix === 'e')
|
|
367
557
|
textual = true;
|
|
368
|
-
|
|
558
|
+
if (prefix === 'u')
|
|
559
|
+
explicitUrl = true;
|
|
560
|
+
add(name, valueOf(prefix, child, base, reading));
|
|
369
561
|
}
|
|
370
562
|
walk(child);
|
|
371
563
|
}
|
|
372
564
|
};
|
|
373
565
|
walk(element);
|
|
374
|
-
|
|
566
|
+
const properties = Object.fromEntries(found);
|
|
567
|
+
implied(element, properties, base, reading, !textual, !explicitUrl);
|
|
375
568
|
return { types: rootTypesOf(element), properties, children, element };
|
|
376
569
|
}
|
|
377
570
|
/** What a nested microformat is worth as a value of the property holding it. */
|
|
378
|
-
function nestedText(prefix, item, element, base) {
|
|
571
|
+
function nestedText(prefix, item, element, base, reading) {
|
|
379
572
|
if (prefix === 'u')
|
|
380
|
-
return first(item, 'url')?.text ?? valueOf('u', element, base).text;
|
|
381
|
-
return first(item, 'name')?.text ??
|
|
573
|
+
return first(item, 'url')?.text ?? valueOf('u', element, base, reading).text;
|
|
574
|
+
return first(item, 'name')?.text ?? textIn(element, reading);
|
|
382
575
|
}
|
|
383
576
|
/** One element as the value of one property. */
|
|
384
|
-
function valueOf(prefix, element, base) {
|
|
577
|
+
function valueOf(prefix, element, base, reading) {
|
|
385
578
|
const attributes = element.attributes;
|
|
386
579
|
if (prefix === 'u') {
|
|
387
580
|
const raw = attributeFor(element, ['a', 'area', 'link'], 'href') ??
|
|
@@ -389,25 +582,26 @@ function valueOf(prefix, element, base) {
|
|
|
389
582
|
attributeFor(element, ['object'], 'data') ??
|
|
390
583
|
attributeFor(element, ['video'], 'poster') ??
|
|
391
584
|
attributeFor(element, ['data'], 'value') ??
|
|
392
|
-
|
|
393
|
-
return { text: normalize(raw, base) ?? raw.trim() };
|
|
585
|
+
textIn(element, reading);
|
|
586
|
+
return { text: normalize(raw, base) ?? raw.trim(), label: textIn(element, reading) };
|
|
394
587
|
}
|
|
395
588
|
if (prefix === 'dt') {
|
|
396
589
|
return {
|
|
397
590
|
text: attributeFor(element, ['time', 'ins', 'del'], 'datetime') ??
|
|
398
591
|
attributeFor(element, ['abbr'], 'title') ??
|
|
399
592
|
attributeFor(element, ['data'], 'value') ??
|
|
400
|
-
|
|
593
|
+
textIn(element, reading),
|
|
401
594
|
};
|
|
402
595
|
}
|
|
403
|
-
if (prefix === 'e')
|
|
404
|
-
return { text:
|
|
596
|
+
if (prefix === 'e') {
|
|
597
|
+
return { text: textIn(element, reading), html: markupIn(element, base, reading) };
|
|
598
|
+
}
|
|
405
599
|
return {
|
|
406
600
|
text: attributeFor(element, ['img', 'area'], 'alt') ??
|
|
407
601
|
attributeFor(element, ['abbr'], 'title') ??
|
|
408
602
|
attributeFor(element, ['data', 'input'], 'value') ??
|
|
409
603
|
(element.name === 'meta' ? attributes['content'] : undefined) ??
|
|
410
|
-
|
|
604
|
+
textIn(element, reading),
|
|
411
605
|
};
|
|
412
606
|
}
|
|
413
607
|
/** One attribute, when the element is one of these and carries it. */
|
|
@@ -426,52 +620,85 @@ function attributeFor(element, names, attribute) {
|
|
|
426
620
|
* actually arrives in and stops short of guessing. A name is implied only when
|
|
427
621
|
* nothing inside is a `p-` or `e-` property or a nested microformat, as mf2
|
|
428
622
|
* says, so an entry with an `e-content` and no `p-name` has no name rather
|
|
429
|
-
* than the text of everything around it.
|
|
623
|
+
* than the text of everything around it. A url is implied from a link inside
|
|
624
|
+
* only when nothing inside is a `u-` property, so a reply's `u-in-reply-to` is
|
|
625
|
+
* not read as the page the reply lives at.
|
|
430
626
|
*/
|
|
431
|
-
function implied(element, properties, base, impliesName) {
|
|
627
|
+
function implied(element, properties, base, reading, impliesName, impliesChildUrl) {
|
|
432
628
|
if (impliesName && properties['name'] === undefined) {
|
|
433
629
|
const name = attributeFor(element, ['img', 'area'], 'alt') ??
|
|
434
630
|
attributeFor(element, ['abbr'], 'title') ??
|
|
435
|
-
|
|
631
|
+
impliedChildName(element) ??
|
|
632
|
+
textIn(element, reading);
|
|
436
633
|
if (name !== '')
|
|
437
634
|
properties['name'] = [{ text: name }];
|
|
438
635
|
}
|
|
439
636
|
if (properties['url'] === undefined) {
|
|
440
637
|
const href = attributeFor(element, ['a', 'area', 'link'], 'href') ??
|
|
441
|
-
|
|
638
|
+
(impliesChildUrl ? impliedAttribute(element, ['a', 'area'], 'href') : undefined);
|
|
442
639
|
const url = href === undefined ? undefined : normalize(href, base);
|
|
443
640
|
if (url !== undefined)
|
|
444
641
|
properties['url'] = [{ text: url }];
|
|
445
642
|
}
|
|
446
643
|
if (properties['photo'] === undefined) {
|
|
447
|
-
const src = attributeFor(element, ['img'], 'src') ??
|
|
644
|
+
const src = attributeFor(element, ['img'], 'src') ?? impliedAttribute(element, ['img'], 'src');
|
|
448
645
|
const photo = src === undefined ? undefined : normalize(src, base);
|
|
449
646
|
if (photo !== undefined)
|
|
450
647
|
properties['photo'] = [{ text: photo }];
|
|
451
648
|
}
|
|
452
649
|
}
|
|
453
650
|
/**
|
|
454
|
-
* The
|
|
455
|
-
*
|
|
651
|
+
* The name an item implies from what is directly inside it, as mf2 reads it:
|
|
652
|
+
* the alt of its only child `img` or `area`, or the title of an only `abbr`,
|
|
653
|
+
* else the same of its only child's only child. An empty one does not count,
|
|
654
|
+
* so a card that is an avatar with a blank alt still reads its text.
|
|
655
|
+
*/
|
|
656
|
+
function impliedChildName(element) {
|
|
657
|
+
const child = onlyChild(element);
|
|
658
|
+
const grandchild = child === undefined ? undefined : onlyChild(child);
|
|
659
|
+
for (const sole of [child, grandchild]) {
|
|
660
|
+
if (sole === undefined)
|
|
661
|
+
continue;
|
|
662
|
+
const name = (attributeFor(sole, ['img', 'area'], 'alt') ?? attributeFor(sole, ['abbr'], 'title'))?.trim();
|
|
663
|
+
if (name !== undefined && name !== '')
|
|
664
|
+
return name;
|
|
665
|
+
}
|
|
666
|
+
return undefined;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* The attribute an item implies from what is directly inside it, as mf2 reads
|
|
670
|
+
* an implied `url` or `photo`: its only child of one of these types, else the
|
|
671
|
+
* only child of that type of its only child element. Nothing that is a
|
|
672
|
+
* microformat of its own counts, and nothing deeper is looked at.
|
|
456
673
|
*
|
|
457
|
-
*
|
|
674
|
+
* Only one of a type, because two links inside a card give no reason to prefer
|
|
458
675
|
* either, and a guess in a byline is worse than an empty one.
|
|
459
676
|
*/
|
|
460
|
-
function
|
|
461
|
-
|
|
462
|
-
for (const
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
if (value === undefined)
|
|
469
|
-
continue;
|
|
470
|
-
if (found !== undefined)
|
|
471
|
-
return undefined;
|
|
472
|
-
found = value;
|
|
677
|
+
function impliedAttribute(element, names, attribute) {
|
|
678
|
+
const sole = onlyChild(element);
|
|
679
|
+
for (const parent of sole === undefined ? [element] : [element, sole]) {
|
|
680
|
+
for (const name of names) {
|
|
681
|
+
const value = onlyOfType(parent, name)?.attributes[attribute];
|
|
682
|
+
if (value !== undefined)
|
|
683
|
+
return value;
|
|
684
|
+
}
|
|
473
685
|
}
|
|
474
|
-
return
|
|
686
|
+
return undefined;
|
|
687
|
+
}
|
|
688
|
+
/** The one child element of this one, when it has exactly one and it is not a microformat. */
|
|
689
|
+
function onlyChild(element) {
|
|
690
|
+
return soleOf(element.children.filter(isElement));
|
|
691
|
+
}
|
|
692
|
+
/** The one child element of this name, when there is exactly one and it is not a microformat. */
|
|
693
|
+
function onlyOfType(element, name) {
|
|
694
|
+
return soleOf(element.children.filter((child) => isElement(child) && child.name === name));
|
|
695
|
+
}
|
|
696
|
+
/** The only element of these, unless there are more or it is a microformat. */
|
|
697
|
+
function soleOf(elements) {
|
|
698
|
+
const [only] = elements;
|
|
699
|
+
return elements.length === 1 && only !== undefined && rootTypesOf(only).length === 0
|
|
700
|
+
? only
|
|
701
|
+
: undefined;
|
|
475
702
|
}
|
|
476
703
|
/** The `<base href>` a page declares, or the URL it was fetched from. */
|
|
477
704
|
function baseOf(root, sourceUrl) {
|
|
@@ -487,6 +714,10 @@ function baseOf(root, sourceUrl) {
|
|
|
487
714
|
}
|
|
488
715
|
return sourceUrl;
|
|
489
716
|
}
|
|
717
|
+
function withoutFragment(url) {
|
|
718
|
+
const hash = url.indexOf('#');
|
|
719
|
+
return hash === -1 ? url : url.slice(0, hash);
|
|
720
|
+
}
|
|
490
721
|
/** One href as an absolute URL, or `undefined` when it is not one. */
|
|
491
722
|
function normalize(href, base) {
|
|
492
723
|
const trimmed = href.trim();
|