@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gouvfr/dsfr-roller",
3
- "version": "1.0.68",
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.68",
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 };
@@ -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
@@ -31,6 +31,7 @@ class Page extends Renderable {
31
31
  boost: this.data.boost,
32
32
  text: this._html.text,
33
33
  section: this.data.section,
34
+ badge: this.data.badge,
34
35
  }
35
36
  }
36
37
 
@@ -1,46 +1,74 @@
1
+ import { BadgesMap } from '../../../page/body/badges-map.js';
2
+
1
3
  class ResultCard {
2
- constructor(data) {
3
- this._title = data.title;
4
- this._url = data.url;
5
- this._desc = data.excerpt ?? data.summary;
6
- this._cover = data.cover || '/static/img/placeholder.16x9.png';
7
- this._section = data.section;
8
- }
9
-
10
- getTags() {
11
- if (!this._section) return '';
12
- return `<div class="fr-card__start">
13
- <ul class="fr-tags-group">
14
- <li>
15
- <p class="fr-tag">${this._section}</p>
16
- </li>
17
- </ul>
18
- </div>`;
19
- }
20
-
21
- getCover() {
22
- if (!this._cover) return '';
23
- return `<div class="fr-card__header">
24
- <div class="fr-card__img">
25
- <img src="${this._cover}" alt="" class="fr-responsive-img">
26
- </div>
27
- </div>`;
28
- }
29
-
30
- render() {
31
- return `<div class="fr-card fr-enlarge-link fr-card--horizontal fr-mb-8v">
32
- <div class="fr-card__body">
33
- <div class="fr-card__content">
34
- <h3 class="fr-card__title">
35
- <a href="${this._url}">${this._title}</a>
36
- </h3>
37
- ${this._desc ? `<p class="fr-card__desc">${this._desc}</p>` : ''}
38
- ${this.getTags()}
39
- </div>
40
- </div>
41
- ${this.getCover()}
42
- </div>`;
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
- 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
- }
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
- async init() {
21
- await window.searchEngine.init('searchPage');
20
+ async init() {
21
+ await window.searchEngine.init('searchPage');
22
22
 
23
- if (this._query) {
24
- this._searchBarInput.value = this._query;
25
- const results = window.searchEngine.search(this._query);
23
+ if (this._query) {
24
+ this._searchBarInput.value = this._query;
25
+ const results = window.searchEngine.search(this._query);
26
26
 
27
- const count = new ResultsCount(results.length);
28
- const resultsList = new ResultsList(results, RESULTS_PER_PAGES);
27
+ const count = new ResultsCount(results.length);
28
+ const resultsList = new ResultsList(results, RESULTS_PER_PAGES);
29
29
 
30
- this._resultsCount.innerHTML = count.render();
31
- document.title = `${document.title} - ${count.render()}`;
30
+ this._resultsCount.innerHTML = count.render();
31
+ document.title = `${document.title} - ${count.render()}`;
32
32
 
33
- this._container.appendChild(resultsList.element);
34
- resultsList.init();
33
+ this._container.appendChild(resultsList.element);
34
+ resultsList.init();
35
35
 
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
- }
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 };