@gouvfr/dsfr-roller 1.0.68 → 1.0.70
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/package.json +2 -2
- package/src/component/components/sidemenu.js +1 -17
- package/src/page/body/badges-map.js +18 -0
- package/src/page/body/badges.js +1 -17
- package/src/page/page.js +1 -0
- package/src/script/search/elements/result-card.js +70 -42
- package/src/script/search/elements/search-page.js +26 -26
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gouvfr/dsfr-roller",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.70",
|
|
4
4
|
"description": "Le module `dsfr-roller` permet de publier le site de documentation du Système de Design de l’État - DSFR",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Système de Design de l'État",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
],
|
|
57
57
|
"main": "./index.js",
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@gouvfr/dsfr-forge": "=1.0.
|
|
59
|
+
"@gouvfr/dsfr-forge": "=1.0.70",
|
|
60
60
|
"@gouvfr/dsfr-publisher": "npm:@gouvfr/dsfr@1.14.2",
|
|
61
61
|
"deepmerge": "^4.3.1",
|
|
62
62
|
"ejs": "^3.1.10",
|
|
@@ -1,23 +1,7 @@
|
|
|
1
1
|
import { Component } from '../component.js';
|
|
2
2
|
import { formatLink } from '../../core/format-link.js';
|
|
3
3
|
import { log } from '@gouvfr/dsfr-forge';
|
|
4
|
-
|
|
5
|
-
const Badges = {
|
|
6
|
-
BETA: {
|
|
7
|
-
id: 'beta',
|
|
8
|
-
type: 'info',
|
|
9
|
-
icon: false,
|
|
10
|
-
size: 'sm',
|
|
11
|
-
},
|
|
12
|
-
NEW: {
|
|
13
|
-
id: 'new',
|
|
14
|
-
type: 'new',
|
|
15
|
-
icon: true,
|
|
16
|
-
size: 'sm',
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const BadgesMap = new Map(Object.values(Badges).map(badge => [badge.id, badge]));
|
|
4
|
+
import { BadgesMap } from '../../page/body/badges-map.js';
|
|
21
5
|
|
|
22
6
|
class Sidemenu extends Component {
|
|
23
7
|
constructor (data, badgeLabels) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const BadgeVariants = {
|
|
2
|
+
BETA: {
|
|
3
|
+
id: 'beta',
|
|
4
|
+
type: 'info',
|
|
5
|
+
icon: false,
|
|
6
|
+
size: 'sm',
|
|
7
|
+
},
|
|
8
|
+
NEW: {
|
|
9
|
+
id: 'new',
|
|
10
|
+
type: 'new',
|
|
11
|
+
icon: true,
|
|
12
|
+
size: 'sm',
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const BadgesMap = new Map(Object.values(BadgeVariants).map(badge => [badge.id, badge]));
|
|
17
|
+
|
|
18
|
+
export { BadgesMap };
|
package/src/page/body/badges.js
CHANGED
|
@@ -1,21 +1,5 @@
|
|
|
1
1
|
import { log } from '@gouvfr/dsfr-forge';
|
|
2
|
-
|
|
3
|
-
const BadgeVariants = {
|
|
4
|
-
BETA: {
|
|
5
|
-
id: 'beta',
|
|
6
|
-
type: 'info',
|
|
7
|
-
icon: false,
|
|
8
|
-
size: 'sm',
|
|
9
|
-
},
|
|
10
|
-
NEW: {
|
|
11
|
-
id: 'new',
|
|
12
|
-
type: 'new',
|
|
13
|
-
icon: true,
|
|
14
|
-
size: 'sm',
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const BadgesMap = new Map(Object.values(BadgeVariants).map(badge => [badge.id, badge]));
|
|
2
|
+
import { BadgesMap } from './badges-map.js';
|
|
19
3
|
|
|
20
4
|
class Badges {
|
|
21
5
|
constructor(data) {
|
package/src/page/page.js
CHANGED
|
@@ -1,46 +1,74 @@
|
|
|
1
|
+
import { BadgesMap } from '../../../page/body/badges-map.js';
|
|
2
|
+
|
|
1
3
|
class ResultCard {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
4
|
+
constructor (data) {
|
|
5
|
+
this._title = data.title;
|
|
6
|
+
this._url = data.url;
|
|
7
|
+
this._desc = data.excerpt ?? data.summary;
|
|
8
|
+
this._cover = data.cover || '/static/img/placeholder.16x9.png';
|
|
9
|
+
this._section = data.section;
|
|
10
|
+
this._badge = data.badge || [];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getTags () {
|
|
14
|
+
if (!this._section) return '';
|
|
15
|
+
return `<div class="fr-card__start">
|
|
16
|
+
<ul class="fr-tags-group">
|
|
17
|
+
<li>
|
|
18
|
+
<p class="fr-tag">${this._section}</p>
|
|
19
|
+
</li>
|
|
20
|
+
</ul>
|
|
21
|
+
</div>`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
getBadges () {
|
|
25
|
+
if (!this._badge?.length) return '';
|
|
26
|
+
|
|
27
|
+
const badges = Array.isArray(this._badge) ? this._badge : this._badge.split(',').map(b => b.trim());
|
|
28
|
+
const badgeItems = badges
|
|
29
|
+
.map(badge => {
|
|
30
|
+
const badgeData = BadgesMap.get(badge);
|
|
31
|
+
if (!badgeData) return null;
|
|
32
|
+
|
|
33
|
+
const badgeLabel = window.resource?.badge?.[badge] || badge;
|
|
34
|
+
let iconClass = '';
|
|
35
|
+
if (badgeData.icon === false) {
|
|
36
|
+
iconClass = ' fr-badge--no-icon';
|
|
37
|
+
} else {
|
|
38
|
+
iconClass = ` fr-badge--icon-${badgeData.icon}`;
|
|
39
|
+
}
|
|
40
|
+
return `<li><span class="fr-badge fr-badge--${badgeData.type} fr-badge--${badgeData.size}${iconClass}">${badgeLabel}</span></li>`;
|
|
41
|
+
})
|
|
42
|
+
.filter(Boolean)
|
|
43
|
+
.join('');
|
|
44
|
+
|
|
45
|
+
return `<ul class="fr-badges-group fr-mb-2v">${badgeItems}</ul>`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getCover () {
|
|
49
|
+
if (!this._cover) return '';
|
|
50
|
+
return `<div class="fr-card__header">
|
|
51
|
+
<div class="fr-card__img">
|
|
52
|
+
<img src="${this._cover}" alt="" class="fr-responsive-img">
|
|
53
|
+
</div>
|
|
54
|
+
${this.getBadges()}
|
|
55
|
+
</div>`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
render () {
|
|
59
|
+
return `<div class="fr-card fr-enlarge-link fr-card--horizontal fr-mb-8v">
|
|
60
|
+
<div class="fr-card__body">
|
|
61
|
+
<div class="fr-card__content">
|
|
62
|
+
<h3 class="fr-card__title">
|
|
63
|
+
<a href="${this._url}">${this._title}</a>
|
|
64
|
+
</h3>
|
|
65
|
+
${this._desc ? `<p class="fr-card__desc">${this._desc}</p>` : ''}
|
|
66
|
+
${this.getTags()}
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
${this.getCover()}
|
|
70
|
+
</div>`;
|
|
71
|
+
}
|
|
44
72
|
}
|
|
45
73
|
|
|
46
74
|
export { ResultCard };
|
|
@@ -7,39 +7,39 @@ import { Pagination } from '../../main/elements/pagination/index.js';
|
|
|
7
7
|
const RESULTS_PER_PAGES = 10;
|
|
8
8
|
|
|
9
9
|
class SearchPage extends Element {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
constructor(element) {
|
|
11
|
+
super(element, 'searchPage');
|
|
12
|
+
|
|
13
|
+
this._query = getQuery();
|
|
14
|
+
this._searchBarInput = document.querySelector('#search-input');
|
|
15
|
+
this._resultsCount = document.querySelector('#results-count');
|
|
16
|
+
this._resultsList = document.querySelector('#results-cards');
|
|
17
|
+
this._container = element.querySelector('#results-page--container');
|
|
18
|
+
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
async init() {
|
|
21
|
+
await window.searchEngine.init('searchPage');
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
if (this._query) {
|
|
24
|
+
this._searchBarInput.value = this._query;
|
|
25
|
+
const results = window.searchEngine.search(this._query);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const count = new ResultsCount(results.length);
|
|
28
|
+
const resultsList = new ResultsList(results, RESULTS_PER_PAGES);
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
this._resultsCount.innerHTML = count.render();
|
|
31
|
+
document.title = `${document.title} - ${count.render()}`;
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
this._container.appendChild(resultsList.element);
|
|
34
|
+
resultsList.init();
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
36
|
+
if (results.length > RESULTS_PER_PAGES) {
|
|
37
|
+
const pagination = new Pagination(results, RESULTS_PER_PAGES);
|
|
38
|
+
this._container.appendChild(pagination.element);
|
|
39
|
+
pagination.init();
|
|
40
|
+
}
|
|
42
41
|
}
|
|
42
|
+
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export { SearchPage };
|