@docusaurus/plugin-content-blog 2.0.0-beta.6f366f4b4 → 2.0.0-beta.7

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.
Files changed (53) hide show
  1. package/lib/.tsbuildinfo +1 -1
  2. package/lib/authors.d.ts +23 -0
  3. package/lib/authors.js +150 -0
  4. package/lib/blogFrontMatter.d.ts +19 -6
  5. package/lib/blogFrontMatter.js +31 -19
  6. package/lib/blogUtils.d.ts +10 -2
  7. package/lib/blogUtils.js +146 -104
  8. package/lib/index.js +76 -70
  9. package/lib/markdownLoader.js +3 -3
  10. package/lib/pluginOptionSchema.d.ts +3 -27
  11. package/lib/pluginOptionSchema.js +19 -7
  12. package/lib/translations.d.ts +10 -0
  13. package/lib/translations.js +53 -0
  14. package/lib/types.d.ts +37 -14
  15. package/package.json +13 -11
  16. package/src/__tests__/__fixtures__/authorsMapFiles/authors.json +29 -0
  17. package/src/__tests__/__fixtures__/authorsMapFiles/authors.yml +27 -0
  18. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad1.json +5 -0
  19. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad1.yml +3 -0
  20. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad2.json +3 -0
  21. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad2.yml +2 -0
  22. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad3.json +8 -0
  23. package/src/__tests__/__fixtures__/authorsMapFiles/authorsBad3.yml +3 -0
  24. package/src/__tests__/__fixtures__/component/Typography.tsx +6 -0
  25. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathEmpty/empty +0 -0
  26. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathJson1/authors.json +0 -0
  27. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathJson2/authors.json +0 -0
  28. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathNestedYml/sub/folder/authors.yml +0 -0
  29. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathYml1/authors.yml +0 -0
  30. package/src/__tests__/__fixtures__/getAuthorsMapFilePath/contentPathYml2/authors.yml +0 -0
  31. package/src/__tests__/__fixtures__/website/blog/2018-12-14-Happy-First-Birthday-Slash.md +3 -0
  32. package/src/__tests__/__fixtures__/website/blog/authors.yml +4 -0
  33. package/src/__tests__/__fixtures__/website/blog/mdx-blog-post.mdx +36 -0
  34. package/src/__tests__/__fixtures__/website/blog/simple-slug.md +4 -0
  35. package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md +3 -0
  36. package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/authors.yml +5 -0
  37. package/src/__tests__/__snapshots__/generateBlogFeed.test.ts.snap +41 -3
  38. package/src/__tests__/__snapshots__/translations.test.ts.snap +64 -0
  39. package/src/__tests__/authors.test.ts +608 -0
  40. package/src/__tests__/blogFrontMatter.test.ts +93 -16
  41. package/src/__tests__/blogUtils.test.ts +94 -0
  42. package/src/__tests__/generateBlogFeed.test.ts +4 -0
  43. package/src/__tests__/index.test.ts +63 -12
  44. package/src/__tests__/pluginOptionSchema.test.ts +3 -3
  45. package/src/__tests__/translations.test.ts +92 -0
  46. package/src/authors.ts +202 -0
  47. package/src/blogFrontMatter.ts +73 -33
  48. package/src/blogUtils.ts +205 -132
  49. package/src/index.ts +92 -61
  50. package/{index.d.ts → src/plugin-content-blog.d.ts} +35 -31
  51. package/src/pluginOptionSchema.ts +22 -9
  52. package/src/translations.ts +63 -0
  53. package/src/types.ts +47 -16
package/src/types.ts CHANGED
@@ -6,27 +6,39 @@
6
6
  */
7
7
 
8
8
  import type {RemarkAndRehypePluginOptions} from '@docusaurus/mdx-loader';
9
- import {
9
+ import type {Tag} from '@docusaurus/utils';
10
+ import type {
10
11
  BrokenMarkdownLink,
11
12
  ContentPaths,
12
13
  } from '@docusaurus/utils/lib/markdownLinks';
14
+ import {Overwrite} from 'utility-types';
13
15
 
14
16
  export type BlogContentPaths = ContentPaths;
15
17
 
16
18
  export interface BlogContent {
19
+ blogSidebarTitle: string;
17
20
  blogPosts: BlogPost[];
18
21
  blogListPaginated: BlogPaginated[];
19
22
  blogTags: BlogTags;
20
23
  blogTagsListPath: string | null;
21
24
  }
22
25
 
23
- export interface DateLink {
24
- date: Date;
25
- link: string;
26
- }
27
-
28
26
  export type FeedType = 'rss' | 'atom';
29
27
 
28
+ export type FeedOptions = {
29
+ type?: FeedType[] | null;
30
+ title?: string;
31
+ description?: string;
32
+ copyright: string;
33
+ language?: string;
34
+ };
35
+
36
+ // Feed options, as provided by user config
37
+ export type UserFeedOptions = Overwrite<
38
+ Partial<FeedOptions>,
39
+ {type?: FeedOptions['type'] | 'all'} // Handle the type: "all" shortcut
40
+ >;
41
+
30
42
  export type EditUrlFunction = (editUrlParams: {
31
43
  blogDirPath: string;
32
44
  blogPath: string;
@@ -34,13 +46,15 @@ export type EditUrlFunction = (editUrlParams: {
34
46
  locale: string;
35
47
  }) => string | undefined;
36
48
 
37
- export interface PluginOptions extends RemarkAndRehypePluginOptions {
49
+ export type PluginOptions = RemarkAndRehypePluginOptions & {
38
50
  id?: string;
39
51
  path: string;
40
52
  routeBasePath: string;
53
+ tagsBasePath: string;
54
+ archiveBasePath: string;
41
55
  include: string[];
42
56
  exclude: string[];
43
- postsPerPage: number;
57
+ postsPerPage: number | 'ALL';
44
58
  blogListComponent: string;
45
59
  blogPostComponent: string;
46
60
  blogTagsListComponent: string;
@@ -52,7 +66,7 @@ export interface PluginOptions extends RemarkAndRehypePluginOptions {
52
66
  truncateMarker: RegExp;
53
67
  showReadingTime: boolean;
54
68
  feedOptions: {
55
- type?: [FeedType] | null;
69
+ type?: FeedType[] | null;
56
70
  title?: string;
57
71
  description?: string;
58
72
  copyright: string;
@@ -61,7 +75,14 @@ export interface PluginOptions extends RemarkAndRehypePluginOptions {
61
75
  editUrl?: string | EditUrlFunction;
62
76
  editLocalizedFiles?: boolean;
63
77
  admonitions: Record<string, unknown>;
64
- }
78
+ authorsMapPath: string;
79
+ };
80
+
81
+ // Options, as provided in the user config (before normalization)
82
+ export type UserPluginOptions = Overwrite<
83
+ Partial<PluginOptions>,
84
+ {feedOptions?: UserFeedOptions}
85
+ >;
65
86
 
66
87
  export interface BlogTags {
67
88
  [key: string]: BlogTag;
@@ -76,6 +97,7 @@ export interface BlogTag {
76
97
  export interface BlogPost {
77
98
  id: string;
78
99
  metadata: MetaData;
100
+ content: string;
79
101
  }
80
102
 
81
103
  export interface BlogPaginatedMetadata {
@@ -95,28 +117,37 @@ export interface BlogPaginated {
95
117
  items: string[];
96
118
  }
97
119
 
120
+ // We allow passing custom fields to authors, e.g., twitter
121
+ export interface Author extends Record<string, unknown> {
122
+ name?: string;
123
+ imageURL?: string;
124
+ url?: string;
125
+ title?: string;
126
+ }
127
+
98
128
  export interface MetaData {
99
129
  permalink: string;
100
130
  source: string;
101
131
  description: string;
102
132
  date: Date;
103
133
  formattedDate: string;
104
- tags: (Tag | string)[];
134
+ tags: Tag[];
105
135
  title: string;
106
136
  readingTime?: number;
107
137
  prevItem?: Paginator;
108
138
  nextItem?: Paginator;
109
139
  truncated: boolean;
110
140
  editUrl?: string;
141
+ authors: Author[];
111
142
  }
112
143
 
113
- export interface Paginator {
114
- title: string;
115
- permalink: string;
144
+ export interface Assets {
145
+ image?: string;
146
+ authorsImageUrls: (string | undefined)[]; // Array of same size as the original MetaData.authors array
116
147
  }
117
148
 
118
- export interface Tag {
119
- label: string;
149
+ export interface Paginator {
150
+ title: string;
120
151
  permalink: string;
121
152
  }
122
153