@docusaurus/plugin-content-blog 2.0.0-beta.677e53d4d → 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 (56) 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 +78 -77
  9. package/lib/markdownLoader.js +3 -3
  10. package/lib/pluginOptionSchema.d.ts +3 -26
  11. package/lib/pluginOptionSchema.js +22 -7
  12. package/lib/translations.d.ts +10 -0
  13. package/lib/translations.js +53 -0
  14. package/lib/types.d.ts +38 -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/_partials/somePartial.md +3 -0
  33. package/src/__tests__/__fixtures__/website/blog/_partials/subfolder/somePartial.md +3 -0
  34. package/src/__tests__/__fixtures__/website/blog/_somePartial.md +3 -0
  35. package/src/__tests__/__fixtures__/website/blog/authors.yml +4 -0
  36. package/src/__tests__/__fixtures__/website/blog/mdx-blog-post.mdx +36 -0
  37. package/src/__tests__/__fixtures__/website/blog/simple-slug.md +4 -0
  38. package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/2018-12-14-Happy-First-Birthday-Slash.md +3 -0
  39. package/src/__tests__/__fixtures__/website/i18n/en/docusaurus-plugin-content-blog/authors.yml +5 -0
  40. package/src/__tests__/__snapshots__/generateBlogFeed.test.ts.snap +81 -3
  41. package/src/__tests__/__snapshots__/translations.test.ts.snap +64 -0
  42. package/src/__tests__/authors.test.ts +608 -0
  43. package/src/__tests__/blogFrontMatter.test.ts +93 -16
  44. package/src/__tests__/blogUtils.test.ts +94 -0
  45. package/src/__tests__/generateBlogFeed.test.ts +7 -1
  46. package/src/__tests__/index.test.ts +63 -12
  47. package/src/__tests__/pluginOptionSchema.test.ts +3 -3
  48. package/src/__tests__/translations.test.ts +92 -0
  49. package/src/authors.ts +202 -0
  50. package/src/blogFrontMatter.ts +73 -33
  51. package/src/blogUtils.ts +206 -131
  52. package/src/index.ts +98 -71
  53. package/{index.d.ts → src/plugin-content-blog.d.ts} +35 -31
  54. package/src/pluginOptionSchema.ts +25 -9
  55. package/src/translations.ts +63 -0
  56. package/src/types.ts +48 -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,12 +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
- postsPerPage: number;
56
+ exclude: string[];
57
+ postsPerPage: number | 'ALL';
43
58
  blogListComponent: string;
44
59
  blogPostComponent: string;
45
60
  blogTagsListComponent: string;
@@ -51,7 +66,7 @@ export interface PluginOptions extends RemarkAndRehypePluginOptions {
51
66
  truncateMarker: RegExp;
52
67
  showReadingTime: boolean;
53
68
  feedOptions: {
54
- type?: [FeedType] | null;
69
+ type?: FeedType[] | null;
55
70
  title?: string;
56
71
  description?: string;
57
72
  copyright: string;
@@ -60,7 +75,14 @@ export interface PluginOptions extends RemarkAndRehypePluginOptions {
60
75
  editUrl?: string | EditUrlFunction;
61
76
  editLocalizedFiles?: boolean;
62
77
  admonitions: Record<string, unknown>;
63
- }
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
+ >;
64
86
 
65
87
  export interface BlogTags {
66
88
  [key: string]: BlogTag;
@@ -75,6 +97,7 @@ export interface BlogTag {
75
97
  export interface BlogPost {
76
98
  id: string;
77
99
  metadata: MetaData;
100
+ content: string;
78
101
  }
79
102
 
80
103
  export interface BlogPaginatedMetadata {
@@ -94,28 +117,37 @@ export interface BlogPaginated {
94
117
  items: string[];
95
118
  }
96
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
+
97
128
  export interface MetaData {
98
129
  permalink: string;
99
130
  source: string;
100
131
  description: string;
101
132
  date: Date;
102
133
  formattedDate: string;
103
- tags: (Tag | string)[];
134
+ tags: Tag[];
104
135
  title: string;
105
136
  readingTime?: number;
106
137
  prevItem?: Paginator;
107
138
  nextItem?: Paginator;
108
139
  truncated: boolean;
109
140
  editUrl?: string;
141
+ authors: Author[];
110
142
  }
111
143
 
112
- export interface Paginator {
113
- title: string;
114
- permalink: string;
144
+ export interface Assets {
145
+ image?: string;
146
+ authorsImageUrls: (string | undefined)[]; // Array of same size as the original MetaData.authors array
115
147
  }
116
148
 
117
- export interface Tag {
118
- label: string;
149
+ export interface Paginator {
150
+ title: string;
119
151
  permalink: string;
120
152
  }
121
153