@azerion/bunosaurus-plugin-content-blog 0.0.0-stage → 4.0.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/README.md +6 -2
- package/assets/atom.css +81 -0
- package/assets/atom.xsl +98 -0
- package/assets/rss.css +81 -0
- package/assets/rss.xsl +92 -0
- package/lib/authors.d.ts +26 -0
- package/lib/authors.js +132 -0
- package/lib/authorsMap.d.ts +24 -0
- package/lib/authorsMap.js +118 -0
- package/lib/authorsProblems.d.ts +21 -0
- package/lib/authorsProblems.js +51 -0
- package/lib/authorsSocials.d.ts +10 -0
- package/lib/authorsSocials.js +68 -0
- package/lib/blogUtils.d.ts +50 -0
- package/lib/blogUtils.js +296 -0
- package/lib/client/contexts.d.ts +33 -0
- package/lib/client/contexts.js +54 -0
- package/lib/client/index.d.ts +9 -0
- package/lib/client/index.js +9 -0
- package/lib/client/sidebarUtils.d.ts +21 -0
- package/lib/client/sidebarUtils.js +49 -0
- package/lib/client/structuredDataUtils.d.ts +10 -0
- package/lib/client/structuredDataUtils.js +130 -0
- package/lib/contentHelpers.d.ts +12 -0
- package/lib/contentHelpers.js +30 -0
- package/lib/feed.d.ts +21 -0
- package/lib/feed.js +250 -0
- package/lib/frontMatter.d.ts +10 -0
- package/lib/frontMatter.js +68 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +275 -0
- package/lib/markdownLoader.d.ts +9 -0
- package/lib/markdownLoader.js +26 -0
- package/lib/options.d.ts +14 -0
- package/lib/options.js +202 -0
- package/lib/props.d.ts +23 -0
- package/lib/props.js +43 -0
- package/lib/readingTime.d.ts +17 -0
- package/lib/readingTime.js +45 -0
- package/lib/remark/footnoteIDFixer.d.ts +14 -0
- package/lib/remark/footnoteIDFixer.js +28 -0
- package/lib/routes.d.ts +18 -0
- package/lib/routes.js +263 -0
- package/lib/translations.d.ts +10 -0
- package/lib/translations.js +40 -0
- package/lib/types.d.ts +11 -0
- package/lib/types.js +8 -0
- package/package.json +70 -4
- package/src/authors.ts +191 -0
- package/src/authorsMap.ts +178 -0
- package/src/authorsProblems.ts +72 -0
- package/src/authorsSocials.ts +86 -0
- package/src/blogUtils.ts +478 -0
- package/src/client/contexts.tsx +95 -0
- package/src/client/index.tsx +24 -0
- package/src/client/sidebarUtils.test.ts +53 -0
- package/src/client/sidebarUtils.tsx +85 -0
- package/src/client/structuredDataUtils.ts +190 -0
- package/src/contentHelpers.ts +35 -0
- package/src/feed.ts +442 -0
- package/src/frontMatter.ts +90 -0
- package/src/index.ts +389 -0
- package/src/markdownLoader.ts +34 -0
- package/src/options.ts +258 -0
- package/src/plugin-content-blog.d.ts +856 -0
- package/src/props.ts +75 -0
- package/src/readingTime.ts +49 -0
- package/src/remark/footnoteIDFixer.ts +29 -0
- package/src/routes.ts +365 -0
- package/src/translations.ts +46 -0
- package/src/types.ts +14 -0
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@docusaurus/plugin-content-blog`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Blog plugin for Docusaurus.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
See [plugin-content-blog documentation](https://docusaurus.io/docs/api/plugins/@docusaurus/plugin-content-blog).
|
package/assets/atom.css
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
main {
|
|
9
|
+
flex: 1 0 auto;
|
|
10
|
+
width: 100%;
|
|
11
|
+
margin: 2rem auto;
|
|
12
|
+
max-width: 800px;
|
|
13
|
+
/* stylelint-disable-next-line font-family-name-quotes */
|
|
14
|
+
font-family:
|
|
15
|
+
system-ui,
|
|
16
|
+
-apple-system,
|
|
17
|
+
'Segoe UI',
|
|
18
|
+
Roboto,
|
|
19
|
+
Ubuntu,
|
|
20
|
+
Cantarell;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.info {
|
|
24
|
+
display: block;
|
|
25
|
+
margin: 2rem 0;
|
|
26
|
+
padding: 1.6rem 2.4rem;
|
|
27
|
+
border: 1px solid dodgerblue;
|
|
28
|
+
border-left-width: 0.5rem;
|
|
29
|
+
border-radius: 0.4rem;
|
|
30
|
+
background-color: #edf5ff;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
a {
|
|
34
|
+
color: #005aff;
|
|
35
|
+
text-decoration: none;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
h1 {
|
|
39
|
+
text-wrap: balance;
|
|
40
|
+
font-size: 3.4rem;
|
|
41
|
+
font-weight: 800;
|
|
42
|
+
margin-bottom: 2rem;
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
h1 .rss-icon {
|
|
48
|
+
height: 3.2rem;
|
|
49
|
+
width: 3.2rem;
|
|
50
|
+
margin-right: 1rem;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
h2 {
|
|
54
|
+
font-size: 2.2rem;
|
|
55
|
+
font-weight: 700;
|
|
56
|
+
margin-bottom: 0.2rem;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
h3 {
|
|
60
|
+
font-size: 1.8rem;
|
|
61
|
+
font-weight: 700;
|
|
62
|
+
margin-bottom: 0.1rem;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.blog-description {
|
|
66
|
+
font-size: 1.4rem;
|
|
67
|
+
margin-bottom: 0.6rem;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.blog-post-date {
|
|
71
|
+
font-size: 1rem;
|
|
72
|
+
line-height: 1.4rem;
|
|
73
|
+
font-style: italic;
|
|
74
|
+
color: #797b7e;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.blog-post-description {
|
|
78
|
+
font-size: 1rem;
|
|
79
|
+
line-height: 1.4rem;
|
|
80
|
+
color: #434349;
|
|
81
|
+
}
|
package/assets/atom.xsl
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
|
2
|
+
<!--
|
|
3
|
+
Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
|
|
5
|
+
This source code is licensed under the MIT license found in the
|
|
6
|
+
LICENSE file in the root directory of this source tree.
|
|
7
|
+
-->
|
|
8
|
+
<xsl:stylesheet
|
|
9
|
+
version="3.0"
|
|
10
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
11
|
+
xmlns:atom="http://www.w3.org/2005/Atom">
|
|
12
|
+
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />
|
|
13
|
+
|
|
14
|
+
<xsl:template match="/">
|
|
15
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
|
16
|
+
<head>
|
|
17
|
+
<title>Atom Feed | <xsl:value-of
|
|
18
|
+
select="atom:feed/atom:title"
|
|
19
|
+
/></title>
|
|
20
|
+
<link rel="stylesheet" href="atom.css" />
|
|
21
|
+
</head>
|
|
22
|
+
<body>
|
|
23
|
+
<main>
|
|
24
|
+
<div class="description">
|
|
25
|
+
<div class="info">
|
|
26
|
+
<strong>This is an Atom feed</strong>. Subscribe by copying the URL
|
|
27
|
+
from the address bar into your newsreader. Visit
|
|
28
|
+
<a href="https://aboutfeeds.com/">About Feeds</a> to learn more
|
|
29
|
+
and get started. It’s free.
|
|
30
|
+
</div>
|
|
31
|
+
<h1>
|
|
32
|
+
<div class="rss-icon">
|
|
33
|
+
<svg
|
|
34
|
+
version="1.1"
|
|
35
|
+
id="Capa_1"
|
|
36
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
37
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
38
|
+
viewBox="0 0 455.731 455.731"
|
|
39
|
+
xml:space="preserve">
|
|
40
|
+
<g>
|
|
41
|
+
<rect
|
|
42
|
+
x="0"
|
|
43
|
+
y="0"
|
|
44
|
+
style="fill: #f78422"
|
|
45
|
+
width="455.731"
|
|
46
|
+
height="455.731"
|
|
47
|
+
/>
|
|
48
|
+
<g>
|
|
49
|
+
<path
|
|
50
|
+
style="fill: #ffffff"
|
|
51
|
+
d="M296.208,159.16C234.445,97.397,152.266,63.382,64.81,63.382v64.348
|
|
52
|
+
c70.268,0,136.288,27.321,185.898,76.931c49.609,49.61,76.931,115.63,76.931,185.898h64.348
|
|
53
|
+
C391.986,303.103,357.971,220.923,296.208,159.16z"
|
|
54
|
+
/>
|
|
55
|
+
<path
|
|
56
|
+
style="fill: #ffffff"
|
|
57
|
+
d="M64.143,172.273v64.348c84.881,0,153.938,69.056,153.938,153.939h64.348
|
|
58
|
+
C282.429,270.196,184.507,172.273,64.143,172.273z"
|
|
59
|
+
/>
|
|
60
|
+
<circle
|
|
61
|
+
style="fill: #ffffff"
|
|
62
|
+
cx="109.833"
|
|
63
|
+
cy="346.26"
|
|
64
|
+
r="46.088"
|
|
65
|
+
/>
|
|
66
|
+
</g>
|
|
67
|
+
</g>
|
|
68
|
+
</svg>
|
|
69
|
+
</div>
|
|
70
|
+
<xsl:value-of select="atom:feed/atom:title" />
|
|
71
|
+
</h1>
|
|
72
|
+
<p class="blog-description">
|
|
73
|
+
<xsl:value-of select="atom:feed/atom:subtitle" />
|
|
74
|
+
</p>
|
|
75
|
+
</div>
|
|
76
|
+
<h2>Recent Posts</h2>
|
|
77
|
+
<div class="blog-posts">
|
|
78
|
+
<xsl:for-each select="atom:feed/atom:entry">
|
|
79
|
+
<div class="blog-post">
|
|
80
|
+
<h3><a href="{atom:link/@href}"><xsl:value-of
|
|
81
|
+
select="atom:title"
|
|
82
|
+
/></a></h3>
|
|
83
|
+
<div class="blog-post-date">
|
|
84
|
+
Published on <xsl:value-of
|
|
85
|
+
select="substring(atom:updated,0,11)"
|
|
86
|
+
/>
|
|
87
|
+
</div>
|
|
88
|
+
<div class="blog-post-description">
|
|
89
|
+
<xsl:value-of select="atom:summary" />
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
</xsl:for-each>
|
|
93
|
+
</div>
|
|
94
|
+
</main>
|
|
95
|
+
</body>
|
|
96
|
+
</html>
|
|
97
|
+
</xsl:template>
|
|
98
|
+
</xsl:stylesheet>
|
package/assets/rss.css
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
main {
|
|
9
|
+
flex: 1 0 auto;
|
|
10
|
+
width: 100%;
|
|
11
|
+
margin: 2rem auto;
|
|
12
|
+
max-width: 800px;
|
|
13
|
+
/* stylelint-disable-next-line font-family-name-quotes */
|
|
14
|
+
font-family:
|
|
15
|
+
system-ui,
|
|
16
|
+
-apple-system,
|
|
17
|
+
'Segoe UI',
|
|
18
|
+
Roboto,
|
|
19
|
+
Ubuntu,
|
|
20
|
+
Cantarell;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.info {
|
|
24
|
+
display: block;
|
|
25
|
+
margin: 2rem 0;
|
|
26
|
+
padding: 1.6rem 2.4rem;
|
|
27
|
+
border: 1px solid dodgerblue;
|
|
28
|
+
border-left-width: 0.5rem;
|
|
29
|
+
border-radius: 0.4rem;
|
|
30
|
+
background-color: #edf5ff;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
a {
|
|
34
|
+
color: #005aff;
|
|
35
|
+
text-decoration: none;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
h1 {
|
|
39
|
+
text-wrap: balance;
|
|
40
|
+
font-size: 3.4rem;
|
|
41
|
+
font-weight: 800;
|
|
42
|
+
margin-bottom: 2rem;
|
|
43
|
+
display: flex;
|
|
44
|
+
align-items: center;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
h1 .rss-icon {
|
|
48
|
+
height: 3.2rem;
|
|
49
|
+
width: 3.2rem;
|
|
50
|
+
margin-right: 1rem;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
h2 {
|
|
54
|
+
font-size: 2.2rem;
|
|
55
|
+
font-weight: 700;
|
|
56
|
+
margin-bottom: 0.2rem;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
h3 {
|
|
60
|
+
font-size: 1.8rem;
|
|
61
|
+
font-weight: 700;
|
|
62
|
+
margin-bottom: 0.1rem;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.blog-description {
|
|
66
|
+
font-size: 1.4rem;
|
|
67
|
+
margin-bottom: 0.6rem;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.blog-post-date {
|
|
71
|
+
font-size: 1rem;
|
|
72
|
+
line-height: 1.4rem;
|
|
73
|
+
font-style: italic;
|
|
74
|
+
color: #797b7e;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.blog-post-description {
|
|
78
|
+
font-size: 1rem;
|
|
79
|
+
line-height: 1.4rem;
|
|
80
|
+
color: #434349;
|
|
81
|
+
}
|
package/assets/rss.xsl
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?>
|
|
2
|
+
<!--
|
|
3
|
+
Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
|
|
5
|
+
This source code is licensed under the MIT license found in the
|
|
6
|
+
LICENSE file in the root directory of this source tree.
|
|
7
|
+
-->
|
|
8
|
+
<xsl:stylesheet
|
|
9
|
+
version="3.0"
|
|
10
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
11
|
+
xmlns:atom="http://www.w3.org/2005/Atom">
|
|
12
|
+
<xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes" />
|
|
13
|
+
|
|
14
|
+
<xsl:template match="/">
|
|
15
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
|
16
|
+
<head>
|
|
17
|
+
<title>RSS Feed | <xsl:value-of select="rss/channel/title" /></title>
|
|
18
|
+
<link rel="stylesheet" href="rss.css" />
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<main>
|
|
22
|
+
<div class="description">
|
|
23
|
+
<div class="info">
|
|
24
|
+
<strong>This is an RSS feed</strong>. Subscribe by copying the URL
|
|
25
|
+
from the address bar into your newsreader. Visit
|
|
26
|
+
<a href="https://aboutfeeds.com/">About Feeds</a> to learn more
|
|
27
|
+
and get started. It’s free.
|
|
28
|
+
</div>
|
|
29
|
+
<h1>
|
|
30
|
+
<div class="rss-icon">
|
|
31
|
+
<svg
|
|
32
|
+
version="1.1"
|
|
33
|
+
id="Capa_1"
|
|
34
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
35
|
+
xmlns:xlink="http://www.w3.org/1999/xlink"
|
|
36
|
+
viewBox="0 0 455.731 455.731"
|
|
37
|
+
xml:space="preserve">
|
|
38
|
+
<g>
|
|
39
|
+
<rect
|
|
40
|
+
x="0"
|
|
41
|
+
y="0"
|
|
42
|
+
style="fill: #f78422"
|
|
43
|
+
width="455.731"
|
|
44
|
+
height="455.731"
|
|
45
|
+
/>
|
|
46
|
+
<g>
|
|
47
|
+
<path
|
|
48
|
+
style="fill: #ffffff"
|
|
49
|
+
d="M296.208,159.16C234.445,97.397,152.266,63.382,64.81,63.382v64.348
|
|
50
|
+
c70.268,0,136.288,27.321,185.898,76.931c49.609,49.61,76.931,115.63,76.931,185.898h64.348
|
|
51
|
+
C391.986,303.103,357.971,220.923,296.208,159.16z"
|
|
52
|
+
/>
|
|
53
|
+
<path
|
|
54
|
+
style="fill: #ffffff"
|
|
55
|
+
d="M64.143,172.273v64.348c84.881,0,153.938,69.056,153.938,153.939h64.348
|
|
56
|
+
C282.429,270.196,184.507,172.273,64.143,172.273z"
|
|
57
|
+
/>
|
|
58
|
+
<circle
|
|
59
|
+
style="fill: #ffffff"
|
|
60
|
+
cx="109.833"
|
|
61
|
+
cy="346.26"
|
|
62
|
+
r="46.088"
|
|
63
|
+
/>
|
|
64
|
+
</g>
|
|
65
|
+
</g>
|
|
66
|
+
</svg>
|
|
67
|
+
</div>
|
|
68
|
+
<xsl:value-of select="rss/channel/title" />
|
|
69
|
+
</h1>
|
|
70
|
+
<p class="blog-description">
|
|
71
|
+
<xsl:value-of select="rss/channel/description" />
|
|
72
|
+
</p>
|
|
73
|
+
</div>
|
|
74
|
+
<h2>Recent Posts</h2>
|
|
75
|
+
<div class="blog-posts">
|
|
76
|
+
<xsl:for-each select="rss/channel/item">
|
|
77
|
+
<div class="blog-post">
|
|
78
|
+
<h3><a href="{link}"><xsl:value-of select="title" /></a></h3>
|
|
79
|
+
<div class="blog-post-date">
|
|
80
|
+
Published on <xsl:value-of select="substring(pubDate,0,17)" />
|
|
81
|
+
</div>
|
|
82
|
+
<div class="blog-post-description">
|
|
83
|
+
<xsl:value-of select="description" />
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</xsl:for-each>
|
|
87
|
+
</div>
|
|
88
|
+
</main>
|
|
89
|
+
</body>
|
|
90
|
+
</html>
|
|
91
|
+
</xsl:template>
|
|
92
|
+
</xsl:stylesheet>
|
package/lib/authors.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Author, AuthorsMap, BlogPost, BlogPostFrontMatter } from '@docusaurus/plugin-content-blog';
|
|
8
|
+
type AuthorsParam = {
|
|
9
|
+
frontMatter: BlogPostFrontMatter;
|
|
10
|
+
authorsMap: AuthorsMap | undefined;
|
|
11
|
+
baseUrl: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function normalizeImageUrl({ imageURL, baseUrl, }: {
|
|
14
|
+
imageURL: string | undefined;
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
}): string | undefined;
|
|
17
|
+
export declare function getBlogPostAuthors(params: AuthorsParam): Author[];
|
|
18
|
+
/**
|
|
19
|
+
* Group blog posts by author key
|
|
20
|
+
* Blog posts with only inline authors are ignored
|
|
21
|
+
*/
|
|
22
|
+
export declare function groupBlogPostsByAuthorKey({ blogPosts, authorsMap, }: {
|
|
23
|
+
blogPosts: BlogPost[];
|
|
24
|
+
authorsMap: AuthorsMap | undefined;
|
|
25
|
+
}): Record<string, BlogPost[]>;
|
|
26
|
+
export {};
|
package/lib/authors.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.normalizeImageUrl = normalizeImageUrl;
|
|
10
|
+
exports.getBlogPostAuthors = getBlogPostAuthors;
|
|
11
|
+
exports.groupBlogPostsByAuthorKey = groupBlogPostsByAuthorKey;
|
|
12
|
+
const tslib_1 = require("tslib");
|
|
13
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
14
|
+
const utils_1 = require("@docusaurus/utils");
|
|
15
|
+
const authorsSocials_1 = require("./authorsSocials");
|
|
16
|
+
function normalizeImageUrl({ imageURL, baseUrl, }) {
|
|
17
|
+
return imageURL?.startsWith('/')
|
|
18
|
+
? (0, utils_1.normalizeUrl)([baseUrl, imageURL])
|
|
19
|
+
: imageURL;
|
|
20
|
+
}
|
|
21
|
+
function normalizeAuthorUrl({ author, baseUrl, }) {
|
|
22
|
+
if (author.key) {
|
|
23
|
+
// Ensures invariant: global authors should have already been normalized
|
|
24
|
+
if (author.imageURL?.startsWith('/') &&
|
|
25
|
+
!author.imageURL.startsWith(baseUrl)) {
|
|
26
|
+
throw new Error(`Docusaurus internal bug: global authors image ${author.imageURL} should start with the expected baseUrl=${baseUrl}`);
|
|
27
|
+
}
|
|
28
|
+
return author.imageURL;
|
|
29
|
+
}
|
|
30
|
+
return normalizeImageUrl({ imageURL: author.imageURL, baseUrl });
|
|
31
|
+
}
|
|
32
|
+
// Legacy v1/early-v2 front matter fields
|
|
33
|
+
// We may want to deprecate those in favor of using only frontMatter.authors
|
|
34
|
+
// TODO Docusaurus v4: remove this legacy front matter
|
|
35
|
+
function getFrontMatterAuthorLegacy({ baseUrl, frontMatter, }) {
|
|
36
|
+
const name = frontMatter.author;
|
|
37
|
+
const title = frontMatter.author_title ?? frontMatter.authorTitle;
|
|
38
|
+
const url = frontMatter.author_url ?? frontMatter.authorURL;
|
|
39
|
+
const imageURL = normalizeImageUrl({
|
|
40
|
+
imageURL: frontMatter.author_image_url ?? frontMatter.authorImageURL,
|
|
41
|
+
baseUrl,
|
|
42
|
+
});
|
|
43
|
+
if (name || title || url || imageURL) {
|
|
44
|
+
return {
|
|
45
|
+
name,
|
|
46
|
+
title,
|
|
47
|
+
url,
|
|
48
|
+
imageURL,
|
|
49
|
+
// legacy front matter authors do not have an author key/page
|
|
50
|
+
key: null,
|
|
51
|
+
page: null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
function getFrontMatterAuthors(params) {
|
|
57
|
+
const { authorsMap, frontMatter, baseUrl } = params;
|
|
58
|
+
return normalizeFrontMatterAuthors().map(toAuthor);
|
|
59
|
+
function normalizeFrontMatterAuthors() {
|
|
60
|
+
if (frontMatter.authors === undefined) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
function normalizeAuthor(authorInput) {
|
|
64
|
+
if (typeof authorInput === 'string') {
|
|
65
|
+
// We could allow users to provide an author's name here, but we only
|
|
66
|
+
// support keys, otherwise, a typo in a key would fall back to
|
|
67
|
+
// becoming a name and may end up unnoticed
|
|
68
|
+
return { key: authorInput };
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
...authorInput,
|
|
72
|
+
socials: (0, authorsSocials_1.normalizeSocials)(authorInput.socials ?? {}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return Array.isArray(frontMatter.authors)
|
|
76
|
+
? frontMatter.authors.map(normalizeAuthor)
|
|
77
|
+
: [normalizeAuthor(frontMatter.authors)];
|
|
78
|
+
}
|
|
79
|
+
function getAuthorsMapAuthor(key) {
|
|
80
|
+
if (key) {
|
|
81
|
+
if (!authorsMap || Object.keys(authorsMap).length === 0) {
|
|
82
|
+
throw new Error(`Can't reference blog post authors by a key (such as '${key}') because no authors map file could be loaded.
|
|
83
|
+
Please double-check your blog plugin config (in particular 'authorsMapPath'), ensure the file exists at the configured path, is not empty, and is valid!`);
|
|
84
|
+
}
|
|
85
|
+
const author = authorsMap[key];
|
|
86
|
+
if (!author) {
|
|
87
|
+
throw Error(`Blog author with key "${key}" not found in the authors map file.
|
|
88
|
+
Valid author keys are:
|
|
89
|
+
${Object.keys(authorsMap)
|
|
90
|
+
.map((validKey) => `- ${validKey}`)
|
|
91
|
+
.join('\n')}`);
|
|
92
|
+
}
|
|
93
|
+
return author;
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
function toAuthor(frontMatterAuthor) {
|
|
98
|
+
const author = {
|
|
99
|
+
// Author def from authorsMap can be locally overridden by front matter
|
|
100
|
+
...getAuthorsMapAuthor(frontMatterAuthor.key),
|
|
101
|
+
...frontMatterAuthor,
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
...author,
|
|
105
|
+
key: author.key ?? null,
|
|
106
|
+
page: author.page ?? null,
|
|
107
|
+
// global author images have already been normalized
|
|
108
|
+
imageURL: normalizeAuthorUrl({ author, baseUrl }),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function getBlogPostAuthors(params) {
|
|
113
|
+
const authorLegacy = getFrontMatterAuthorLegacy(params);
|
|
114
|
+
const authors = getFrontMatterAuthors(params);
|
|
115
|
+
if (authorLegacy) {
|
|
116
|
+
// Technically, we could allow mixing legacy/authors front matter, but do we
|
|
117
|
+
// really want to?
|
|
118
|
+
if (authors.length > 0) {
|
|
119
|
+
throw new Error(`To declare blog post authors, use the 'authors' front matter in priority.
|
|
120
|
+
Don't mix 'authors' with other existing 'author_*' front matter. Choose one or the other, not both at the same time.`);
|
|
121
|
+
}
|
|
122
|
+
return [authorLegacy];
|
|
123
|
+
}
|
|
124
|
+
return authors;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Group blog posts by author key
|
|
128
|
+
* Blog posts with only inline authors are ignored
|
|
129
|
+
*/
|
|
130
|
+
function groupBlogPostsByAuthorKey({ blogPosts, authorsMap, }) {
|
|
131
|
+
return lodash_1.default.mapValues(authorsMap, (author, key) => blogPosts.filter((p) => p.metadata.authors.some((a) => a.key === key)));
|
|
132
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { BlogContentPaths } from './types';
|
|
8
|
+
import type { AuthorAttributes, AuthorPage, AuthorsMap } from '@docusaurus/plugin-content-blog';
|
|
9
|
+
type AuthorInput = AuthorAttributes & {
|
|
10
|
+
page?: boolean | AuthorPage;
|
|
11
|
+
};
|
|
12
|
+
export type AuthorsMapInput = {
|
|
13
|
+
[authorKey: string]: AuthorInput;
|
|
14
|
+
};
|
|
15
|
+
export declare function checkAuthorsMapPermalinkCollisions(authorsMap: AuthorsMap | undefined): void;
|
|
16
|
+
export declare function validateAuthorsMapInput(content: unknown): AuthorsMapInput;
|
|
17
|
+
export declare function getAuthorsMap(params: {
|
|
18
|
+
authorsMapPath: string;
|
|
19
|
+
authorsBaseRoutePath: string;
|
|
20
|
+
contentPaths: BlogContentPaths;
|
|
21
|
+
baseUrl: string;
|
|
22
|
+
}): Promise<AuthorsMap | undefined>;
|
|
23
|
+
export declare function validateAuthorsMap(content: unknown): AuthorsMapInput;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.checkAuthorsMapPermalinkCollisions = checkAuthorsMapPermalinkCollisions;
|
|
10
|
+
exports.validateAuthorsMapInput = validateAuthorsMapInput;
|
|
11
|
+
exports.getAuthorsMap = getAuthorsMap;
|
|
12
|
+
exports.validateAuthorsMap = validateAuthorsMap;
|
|
13
|
+
const tslib_1 = require("tslib");
|
|
14
|
+
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
15
|
+
const utils_1 = require("@docusaurus/utils");
|
|
16
|
+
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
17
|
+
const authorsSocials_1 = require("./authorsSocials");
|
|
18
|
+
const authors_1 = require("./authors");
|
|
19
|
+
const AuthorPageSchema = utils_validation_1.Joi.object({
|
|
20
|
+
permalink: utils_validation_1.Joi.string().required(),
|
|
21
|
+
});
|
|
22
|
+
const AuthorsMapInputSchema = utils_validation_1.Joi.object()
|
|
23
|
+
.pattern(utils_validation_1.Joi.string(), utils_validation_1.Joi.object({
|
|
24
|
+
name: utils_validation_1.Joi.string(),
|
|
25
|
+
url: utils_validation_1.URISchema,
|
|
26
|
+
imageURL: utils_validation_1.URISchema,
|
|
27
|
+
title: utils_validation_1.Joi.string(),
|
|
28
|
+
email: utils_validation_1.Joi.string(),
|
|
29
|
+
page: utils_validation_1.Joi.alternatives(utils_validation_1.Joi.bool(), AuthorPageSchema),
|
|
30
|
+
socials: authorsSocials_1.AuthorSocialsSchema,
|
|
31
|
+
description: utils_validation_1.Joi.string(),
|
|
32
|
+
})
|
|
33
|
+
.rename('image_url', 'imageURL')
|
|
34
|
+
.or('name', 'imageURL')
|
|
35
|
+
.unknown()
|
|
36
|
+
.required()
|
|
37
|
+
.messages({
|
|
38
|
+
'object.base': '{#label} should be an author object containing properties like name, title, and imageURL.',
|
|
39
|
+
'any.required': '{#label} cannot be undefined. It should be an author object containing properties like name, title, and imageURL.',
|
|
40
|
+
}))
|
|
41
|
+
.messages({
|
|
42
|
+
'object.base': "The authors map file should contain an object where each entry contains an author key and the corresponding author's data.",
|
|
43
|
+
});
|
|
44
|
+
function checkAuthorsMapPermalinkCollisions(authorsMap) {
|
|
45
|
+
if (!authorsMap) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const permalinkCounts = (0, lodash_1.default)(authorsMap)
|
|
49
|
+
// Filter to keep only authors with a page
|
|
50
|
+
.pickBy((author) => !!author.page)
|
|
51
|
+
// Group authors by their permalink
|
|
52
|
+
.groupBy((author) => author.page?.permalink)
|
|
53
|
+
// Filter to keep only permalinks with more than one author
|
|
54
|
+
.pickBy((authors) => authors.length > 1)
|
|
55
|
+
// Transform the object into an array of [permalink, authors] pairs
|
|
56
|
+
.toPairs()
|
|
57
|
+
.value();
|
|
58
|
+
if (permalinkCounts.length > 0) {
|
|
59
|
+
const errorMessage = permalinkCounts
|
|
60
|
+
.map(([permalink, authors]) => `Permalink: ${permalink}\nAuthors: ${authors
|
|
61
|
+
.map((author) => author.name || 'Unknown')
|
|
62
|
+
.join(', ')}`)
|
|
63
|
+
.join('\n');
|
|
64
|
+
throw new Error(`The following permalinks are duplicated:\n${errorMessage}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function normalizeAuthor({ authorsBaseRoutePath, authorKey, baseUrl, author, }) {
|
|
68
|
+
function getAuthorPage() {
|
|
69
|
+
if (!author.page) {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const slug = author.page === true ? lodash_1.default.kebabCase(authorKey) : author.page.permalink;
|
|
73
|
+
return {
|
|
74
|
+
permalink: (0, utils_1.normalizeUrl)([authorsBaseRoutePath, slug]),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
...author,
|
|
79
|
+
key: authorKey,
|
|
80
|
+
page: getAuthorPage(),
|
|
81
|
+
imageURL: (0, authors_1.normalizeImageUrl)({ imageURL: author.imageURL, baseUrl }),
|
|
82
|
+
socials: author.socials ? (0, authorsSocials_1.normalizeSocials)(author.socials) : undefined,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function normalizeAuthorsMap({ authorsBaseRoutePath, authorsMapInput, baseUrl, }) {
|
|
86
|
+
return lodash_1.default.mapValues(authorsMapInput, (author, authorKey) => {
|
|
87
|
+
return normalizeAuthor({ authorsBaseRoutePath, authorKey, author, baseUrl });
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function validateAuthorsMapInput(content) {
|
|
91
|
+
const { error, value } = AuthorsMapInputSchema.validate(content);
|
|
92
|
+
if (error) {
|
|
93
|
+
throw error;
|
|
94
|
+
}
|
|
95
|
+
return value;
|
|
96
|
+
}
|
|
97
|
+
async function getAuthorsMapInput(params) {
|
|
98
|
+
const content = await (0, utils_1.readDataFile)({
|
|
99
|
+
filePath: params.authorsMapPath,
|
|
100
|
+
contentPaths: params.contentPaths,
|
|
101
|
+
});
|
|
102
|
+
return content ? validateAuthorsMapInput(content) : undefined;
|
|
103
|
+
}
|
|
104
|
+
async function getAuthorsMap(params) {
|
|
105
|
+
const authorsMapInput = await getAuthorsMapInput(params);
|
|
106
|
+
if (!authorsMapInput) {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
const authorsMap = normalizeAuthorsMap({ authorsMapInput, ...params });
|
|
110
|
+
return authorsMap;
|
|
111
|
+
}
|
|
112
|
+
function validateAuthorsMap(content) {
|
|
113
|
+
const { error, value } = AuthorsMapInputSchema.validate(content);
|
|
114
|
+
if (error) {
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Author, PluginOptions } from '@docusaurus/plugin-content-blog';
|
|
8
|
+
export declare function reportAuthorsProblems(params: {
|
|
9
|
+
authors: Author[];
|
|
10
|
+
blogSourceRelative: string;
|
|
11
|
+
options: Pick<PluginOptions, 'onInlineAuthors' | 'authorsMapPath'>;
|
|
12
|
+
}): void;
|
|
13
|
+
export declare function reportInlineAuthors({ authors, blogSourceRelative, options: { onInlineAuthors, authorsMapPath }, }: {
|
|
14
|
+
authors: Author[];
|
|
15
|
+
blogSourceRelative: string;
|
|
16
|
+
options: Pick<PluginOptions, 'onInlineAuthors' | 'authorsMapPath'>;
|
|
17
|
+
}): void;
|
|
18
|
+
export declare function reportDuplicateAuthors({ authors, blogSourceRelative, }: {
|
|
19
|
+
authors: Author[];
|
|
20
|
+
blogSourceRelative: string;
|
|
21
|
+
}): void;
|