hds-web 1.25.7 → 1.25.8

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": "hds-web",
3
- "version": "1.25.7",
3
+ "version": "1.25.8",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.es.js",
@@ -2,14 +2,17 @@ function buildInvertedIndex(data) {
2
2
  const invertedIndex = {};
3
3
 
4
4
  for (const item of data) {
5
- const key = Object.keys(item)[0];
6
- const tags = item[key];
5
+ const attributes = item.attributes;
7
6
 
8
- for (const tag of tags) {
9
- if (!invertedIndex[tag]) {
10
- invertedIndex[tag] = new Set();
7
+ if (attributes && attributes.hashtags) {
8
+ const tags = attributes.hashtags.map(tag => tag.tag);
9
+
10
+ for (const tag of tags) {
11
+ if (!invertedIndex[tag]) {
12
+ invertedIndex[tag] = new Set();
13
+ }
14
+ invertedIndex[tag].add(item);
11
15
  }
12
- invertedIndex[tag].add(key);
13
16
  }
14
17
  }
15
18
 
@@ -18,17 +21,18 @@ function buildInvertedIndex(data) {
18
21
 
19
22
  export default function getSimilarAndRemainingKeys(data, inputKey) {
20
23
  const invertedIndex = buildInvertedIndex(data);
21
- const inputTags = data.find(item => item[inputKey]);
24
+ const inputTagsItem = data.find(item => item.attributes && item.attributes.slug === inputKey);
22
25
  const similarKeys = new Set();
23
26
  const allKeys = new Set();
24
27
 
25
- if (inputTags) {
26
- for (const tag of inputTags[inputKey]) {
27
- const keysWithSimilarTag = invertedIndex[tag];
28
- if (keysWithSimilarTag) {
29
- keysWithSimilarTag.forEach(key => {
30
- if (key !== inputKey) {
31
- similarKeys.add(key);
28
+ if (inputTagsItem && inputTagsItem.attributes && inputTagsItem.attributes.hashtags) {
29
+ const tags = inputTagsItem.attributes.hashtags.map(tag => tag.tag);
30
+ for (const tag of tags) {
31
+ const itemsWithSimilarTag = invertedIndex[tag];
32
+ if (itemsWithSimilarTag) {
33
+ itemsWithSimilarTag.forEach(item => {
34
+ if (item.attributes.slug !== inputKey) {
35
+ similarKeys.add(item.attributes.slug);
32
36
  }
33
37
  });
34
38
  }
@@ -36,12 +40,10 @@ export default function getSimilarAndRemainingKeys(data, inputKey) {
36
40
  }
37
41
 
38
42
  for (const item of data) {
39
- const key = Object.keys(item)[0];
40
- allKeys.add(key);
43
+ allKeys.add(item.attributes.slug);
41
44
  }
42
45
 
43
46
  const remainingKeys = [...allKeys].filter(key => !similarKeys.has(key));
44
47
 
45
48
  return [...similarKeys, ...remainingKeys];
46
49
  }
47
-