@datagouv/components-next 1.4.1-dev.1352.g1b2862b2 → 1.4.1-dev.1355.g54710cb7
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/dist/components-next.js +8431 -8386
- package/package.json +2 -1
- package/src/components/MarkdownViewer.vue +4 -1
- package/src/functions/markdown.ts +10 -1
- package/src/main.ts +14 -7
- package/src/types/pages.ts +70 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@datagouv/components-next",
|
|
3
|
-
"version": "1.4.1-dev.
|
|
3
|
+
"version": "1.4.1-dev.1355.g54710cb7",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"pdfjs-dist": "^4.10.38",
|
|
43
43
|
"pmtiles": "^4.5.0",
|
|
44
44
|
"popmotion": "^11.0.5",
|
|
45
|
+
"rehype-external-links": "^3.0.0",
|
|
45
46
|
"rehype-highlight": "^7.0.2",
|
|
46
47
|
"rehype-raw": "^7.0.0",
|
|
47
48
|
"rehype-sanitize": "^6.0.0",
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<template>
|
|
3
3
|
<div
|
|
4
4
|
:class="size === 'sm' ? markdownSmClasses : markdownClasses"
|
|
5
|
-
v-html="formatMarkdown(content, { minDepth: minHeading, noHeadings })"
|
|
5
|
+
v-html="formatMarkdown(content, { minDepth: minHeading, noHeadings, followLinks })"
|
|
6
6
|
/>
|
|
7
7
|
</template>
|
|
8
8
|
|
|
@@ -14,9 +14,12 @@ withDefaults(defineProps<{
|
|
|
14
14
|
minHeading?: 1 | 2 | 3 | 4 | 5 | 6
|
|
15
15
|
noHeadings?: boolean
|
|
16
16
|
size?: 'sm' | 'md'
|
|
17
|
+
// Only for content written by the team, see formatMarkdown.
|
|
18
|
+
followLinks?: boolean
|
|
17
19
|
}>(), {
|
|
18
20
|
minHeading: 3,
|
|
19
21
|
size: 'sm',
|
|
20
22
|
noHeadings: false,
|
|
23
|
+
followLinks: false,
|
|
21
24
|
})
|
|
22
25
|
</script>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type hast from 'hast'
|
|
2
2
|
import behead, { type Options } from 'remark-behead'
|
|
3
3
|
import remarkBreaks from 'remark-breaks'
|
|
4
|
+
import rehypeExternalLinks from 'rehype-external-links'
|
|
4
5
|
import rehypeHighlight from 'rehype-highlight'
|
|
5
6
|
import remarkParse from 'remark-parse'
|
|
6
7
|
import remarkRehype from 'remark-rehype'
|
|
@@ -57,15 +58,17 @@ function rehypeNoHeadings(this: Processor): Transformer {
|
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
export function formatMarkdown(md: string, config: number | { minDepth: number, noHeadings: boolean } = 3) {
|
|
61
|
+
export function formatMarkdown(md: string, config: number | { minDepth: number, noHeadings: boolean, followLinks?: boolean } = 3) {
|
|
61
62
|
let minDepth: number
|
|
62
63
|
let noHeadings = false
|
|
64
|
+
let followLinks = false
|
|
63
65
|
if (typeof config === 'number') {
|
|
64
66
|
minDepth = config
|
|
65
67
|
}
|
|
66
68
|
else {
|
|
67
69
|
minDepth = config.minDepth
|
|
68
70
|
noHeadings = config.noHeadings
|
|
71
|
+
followLinks = config.followLinks ?? false
|
|
69
72
|
}
|
|
70
73
|
const result = unified()
|
|
71
74
|
.use(behead, { minDepth: minDepth > 1 ? minDepth : undefined } as Options)
|
|
@@ -84,6 +87,12 @@ export function formatMarkdown(md: string, config: number | { minDepth: number,
|
|
|
84
87
|
.use(rehypeHighlight)
|
|
85
88
|
.use(rehypeSlug)
|
|
86
89
|
.use(rehypeSanitize)
|
|
90
|
+
// Markdown mostly comes from users: links leaving the site must not pass on its search
|
|
91
|
+
// ranking, or they become worth spamming for. `followLinks` is for content written by the team.
|
|
92
|
+
.use(rehypeExternalLinks, {
|
|
93
|
+
rel: followLinks ? [] : ['ugc', 'nofollow', 'noopener'],
|
|
94
|
+
protocols: ['http', 'https', 'mailto'],
|
|
95
|
+
})
|
|
87
96
|
// Serialize syntax tree to HTML
|
|
88
97
|
.use(rehypeStringify)
|
|
89
98
|
.use(noHeadings ? [rehypeLazyLoad, rehypeNoHeadings] : [rehypeLazyLoad])
|
package/src/main.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { License } from './types/licenses'
|
|
|
13
13
|
import type { Member, MemberRole, NewOrganization, Organization, OrganizationOrSuggest, OrganizationReference, OrganizationSuggest } from './types/organizations'
|
|
14
14
|
import type { Owned, OwnedWithFullObject, OwnedWithId } from './types/owned'
|
|
15
15
|
import type { Comment, Thread } from './types/discussions'
|
|
16
|
-
import type { PageBloc,
|
|
16
|
+
import type { PageBloc, SectionBloc, SectionContentBloc, BlocWidth, LeafBloc, ObjectBloc, TitleBloc, DatasetBloc, DataserviceBloc, ReuseBloc, ExploreBloc, LinkInBloc, LinksListBloc, MarkdownBloc, AccordionContentBloc, AccordionItemBloc, AccordionListBloc, ButtonBloc, SectionColor } from './types/pages'
|
|
17
17
|
import type { Post, PostAncestor } from './types/posts'
|
|
18
18
|
import type { ReuseReference, NewReuse, Reuse, ReuseV2, ReuseTopic, ReuseType } from './types/reuses'
|
|
19
19
|
import type { RegisteredSchema, Schema, SchemaDetails, SchemaField, SchemaPath, SchemaPublicationMode, SchemaResponseData, SchemaVersion, ValidataError } from './types/schemas'
|
|
@@ -216,17 +216,24 @@ export type {
|
|
|
216
216
|
OwnedWithFullObject,
|
|
217
217
|
OwnedWithId,
|
|
218
218
|
PageBloc,
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
219
|
+
SectionBloc,
|
|
220
|
+
SectionContentBloc,
|
|
221
|
+
BlocWidth,
|
|
222
|
+
LeafBloc,
|
|
223
|
+
ObjectBloc,
|
|
224
|
+
TitleBloc,
|
|
225
|
+
DatasetBloc,
|
|
226
|
+
DataserviceBloc,
|
|
227
|
+
ReuseBloc,
|
|
228
|
+
ExploreBloc,
|
|
224
229
|
LinkInBloc,
|
|
225
230
|
LinksListBloc,
|
|
226
231
|
MarkdownBloc,
|
|
232
|
+
AccordionContentBloc,
|
|
227
233
|
AccordionItemBloc,
|
|
228
234
|
AccordionListBloc,
|
|
229
|
-
|
|
235
|
+
ButtonBloc,
|
|
236
|
+
SectionColor,
|
|
230
237
|
PaginatedArray,
|
|
231
238
|
Post,
|
|
232
239
|
PostAncestor,
|
package/src/types/pages.ts
CHANGED
|
@@ -2,23 +2,24 @@ import type { DatasetV2 } from './datasets'
|
|
|
2
2
|
import type { Dataservice } from './dataservices'
|
|
3
3
|
import type { Reuse } from './reuses'
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type BlocWidth = '1/4' | '1/3' | '1/2' | '2/3' | '3/4'
|
|
6
|
+
|
|
7
|
+
// Blocs inside a section or an accordion item sit side by side, wrapping to a new row when
|
|
8
|
+
// the row is full. `null`: the whole row.
|
|
9
|
+
type Sized = { width: BlocWidth | null }
|
|
10
|
+
|
|
11
|
+
export type TitleBloc = Sized & {
|
|
12
|
+
class: 'TitleBloc'
|
|
13
|
+
id: string
|
|
6
14
|
title: string
|
|
7
15
|
subtitle: string | null
|
|
8
16
|
}
|
|
9
17
|
|
|
10
|
-
export type
|
|
11
|
-
class: '
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class: 'DataservicesListBloc'
|
|
16
|
-
dataservices: Array<Dataservice>
|
|
17
|
-
} & BlocWithTitle & { id: string }
|
|
18
|
-
export type ReusesListBloc = {
|
|
19
|
-
class: 'ReusesListBloc'
|
|
20
|
-
reuses: Array<Reuse>
|
|
21
|
-
} & BlocWithTitle & { id: string }
|
|
18
|
+
export type MarkdownBloc = Sized & {
|
|
19
|
+
class: 'MarkdownBloc'
|
|
20
|
+
id: string
|
|
21
|
+
content: string
|
|
22
|
+
}
|
|
22
23
|
|
|
23
24
|
export type LinkInBloc = {
|
|
24
25
|
title: string
|
|
@@ -26,40 +27,72 @@ export type LinkInBloc = {
|
|
|
26
27
|
color: string | null
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
export type LinksListBloc = {
|
|
30
|
+
export type LinksListBloc = Sized & {
|
|
30
31
|
class: 'LinksListBloc'
|
|
31
|
-
|
|
32
|
-
main_link_title: string | null
|
|
33
|
-
main_link_url: string | null
|
|
32
|
+
id: string
|
|
34
33
|
links: Array<LinkInBloc>
|
|
35
|
-
}
|
|
34
|
+
}
|
|
36
35
|
|
|
37
|
-
export type
|
|
38
|
-
class: '
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
export type ButtonBloc = Sized & {
|
|
37
|
+
class: 'ButtonBloc'
|
|
38
|
+
id: string
|
|
39
|
+
title: string
|
|
40
|
+
url: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ExploreBloc = Sized & {
|
|
44
|
+
class: 'ExploreBloc'
|
|
45
|
+
id: string
|
|
46
|
+
resource_id: string
|
|
47
|
+
}
|
|
41
48
|
|
|
42
|
-
export type
|
|
49
|
+
export type DatasetBloc = Sized & {
|
|
50
|
+
class: 'DatasetBloc'
|
|
51
|
+
id: string
|
|
52
|
+
dataset: DatasetV2
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type DataserviceBloc = Sized & {
|
|
56
|
+
class: 'DataserviceBloc'
|
|
57
|
+
id: string
|
|
58
|
+
dataservice: Dataservice
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type ReuseBloc = Sized & {
|
|
62
|
+
class: 'ReuseBloc'
|
|
63
|
+
id: string
|
|
64
|
+
reuse: Reuse
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export type ObjectBloc = DatasetBloc | DataserviceBloc | ReuseBloc
|
|
68
|
+
|
|
69
|
+
export type LeafBloc = TitleBloc | MarkdownBloc | LinksListBloc | ButtonBloc | ExploreBloc | ObjectBloc
|
|
70
|
+
|
|
71
|
+
export type AccordionContentBloc = Exclude<LeafBloc, ExploreBloc>
|
|
43
72
|
|
|
44
73
|
export type AccordionItemBloc = {
|
|
74
|
+
id: string
|
|
45
75
|
title: string
|
|
46
|
-
content: Array<
|
|
76
|
+
content: Array<AccordionContentBloc>
|
|
47
77
|
}
|
|
48
78
|
|
|
49
|
-
export type AccordionListBloc = {
|
|
79
|
+
export type AccordionListBloc = Sized & {
|
|
50
80
|
class: 'AccordionListBloc'
|
|
51
|
-
|
|
52
|
-
description: string | null
|
|
81
|
+
id: string
|
|
53
82
|
items: Array<AccordionItemBloc>
|
|
54
|
-
}
|
|
83
|
+
}
|
|
55
84
|
|
|
56
|
-
export type
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
85
|
+
export type SectionContentBloc = AccordionListBloc | LeafBloc
|
|
86
|
+
|
|
87
|
+
export type SectionColor = 'primary' | 'green' | 'purple'
|
|
88
|
+
|
|
89
|
+
export type SectionBloc = {
|
|
90
|
+
class: 'SectionBloc'
|
|
91
|
+
id: string
|
|
92
|
+
// `null`: the sections of the page alternate their neutral backgrounds.
|
|
93
|
+
color: SectionColor | null
|
|
94
|
+
blocs: Array<SectionContentBloc>
|
|
95
|
+
}
|
|
64
96
|
|
|
65
|
-
|
|
97
|
+
// The blocs of a page, from the top.
|
|
98
|
+
export type PageBloc = SectionBloc
|