@jungvonmatt/cssg-plugin-hugo 1.4.9 → 1.4.12

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 (3) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/index.js +39 -19
  3. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -3,6 +3,39 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.4.12](https://github.com/jungvonmatt/contentful-ssg/compare/v1.4.11...v1.4.12) (2022-02-23)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix syntax error ([53ac989](https://github.com/jungvonmatt/contentful-ssg/commit/53ac989b9ba92b5c8ccd8759c77b17cf6dcebd22))
12
+
13
+
14
+
15
+
16
+
17
+ ## [1.4.11](https://github.com/jungvonmatt/contentful-ssg/compare/v1.4.10...v1.4.11) (2022-02-23)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **hugo-menu:** makes menu roots configurable ([ac10c2f](https://github.com/jungvonmatt/contentful-ssg/commit/ac10c2f73646016d3ac69fd96f8a2ebca2247043))
23
+
24
+
25
+
26
+
27
+
28
+ ## [1.4.10](https://github.com/jungvonmatt/contentful-ssg/compare/v1.4.9...v1.4.10) (2022-02-22)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * **hugo-locales:** Lowercase ISO locale codes to work with hugo ([088cb0b](https://github.com/jungvonmatt/contentful-ssg/commit/088cb0b871e3d93fb75641a5c031e61011838cda))
34
+
35
+
36
+
37
+
38
+
6
39
  ## [1.4.9](https://github.com/jungvonmatt/contentful-ssg/compare/v1.4.8...v1.4.9) (2022-02-11)
7
40
 
8
41
  **Note:** Version bump only for package @jungvonmatt/cssg-plugin-hugo
package/index.js CHANGED
@@ -26,11 +26,19 @@ const defaultOptions = {
26
26
  fieldIdMenuEntries: 'entries',
27
27
  fieldIdMenuHide: 'hide_in_menu',
28
28
  fieldIdMenuPos: 'menu_pos',
29
+ menuRootTypes: ['page', 'folder', 'x-folder'],
29
30
  typeConfig: {
30
31
  [TYPE_CONTENT]: ['page'],
31
32
  },
32
33
  };
33
34
 
35
+ // Currently Hugo language internals lowercase language codes,
36
+ // which can cause conflicts with settings like defaultContentLanguage
37
+ // which are not lowercased
38
+ // See https://github.com/gohugoio/hugo/issues/7344
39
+ // https://gohugo.io/content-management/multilingual/#configure-languages
40
+ const hugoLocaleCode = (locale) => locale.code.toLowerCase();
41
+
34
42
  export default (args) => {
35
43
  const options = { ...defaultOptions, ...(args || {}) };
36
44
 
@@ -88,7 +96,7 @@ export default (args) => {
88
96
  const node = entryMap.get(id);
89
97
  const contentType = node?.sys?.contentType?.sys?.id ?? '';
90
98
  const pageId = node?.fields?.link_to_entry?.sys?.id;
91
- if (contentType === 'page') {
99
+ if (options.menuRootTypes.includes(contentType)) {
92
100
  return node;
93
101
  }
94
102
 
@@ -215,15 +223,25 @@ export default (args) => {
215
223
  // Write config yaml according to locale settings in contentful
216
224
  if (options.languageConfig) {
217
225
  const rootDir = runtimeContext?.config?.rootDir ?? process.cwd();
226
+ const mainConfigFile = path.join(rootDir, 'config/_default/config.yaml');
227
+ const mainConfig = converter.yaml.parse(await readFile(mainConfigFile));
228
+ const defaultLocale = locales.find((locale) => locale.default);
229
+ if (defaultLocale && mainConfig.languageCode) {
230
+ mainConfig.languageCode = hugoLocaleCode(defaultLocale);
231
+ }
232
+
233
+ if (defaultLocale && mainConfig.defaultContentLanguage) {
234
+ mainConfig.defaultContentLanguage = hugoLocaleCode(defaultLocale);
235
+ }
236
+
237
+ await outputFile(mainConfigFile, converter.yaml.stringify(mainConfig));
238
+
218
239
  const dst = path.join(rootDir, 'config/_default/languages.yaml');
219
240
  const languageConfig = Object.fromEntries(
220
241
  locales.map((locale) => {
221
242
  const { code, name: languageName } = locale;
222
- // Currently Hugo language internals lowercase language codes,
223
- // which can cause conflicts with settings like defaultContentLanguage
224
- // which are not lowercased
225
- // https://github.com/gohugoio/hugo/issues/7344
226
- const languageCode = code.toLowerCase();
243
+
244
+ const languageCode = code;
227
245
  const [languageNameShort] = languageCode.split('-');
228
246
 
229
247
  const localeConfig = {
@@ -234,9 +252,9 @@ export default (args) => {
234
252
  };
235
253
 
236
254
  return [
237
- code,
255
+ hugoLocaleCode(locale),
238
256
  options.translationStrategy === 'directory'
239
- ? { contentDir: `content/${languageCode}`, ...localeConfig }
257
+ ? { contentDir: `content/${hugoLocaleCode(locale)}`, ...localeConfig }
240
258
  : localeConfig,
241
259
  ];
242
260
  })
@@ -260,8 +278,8 @@ export default (args) => {
260
278
  })
261
279
  );
262
280
 
263
- const i18n = Object.fromEntries(locales.map((locale) => [locale.code, {}]));
264
- const menus = Object.fromEntries(locales.map((locale) => [locale.code, {}]));
281
+ const i18n = Object.fromEntries(locales.map((locale) => [hugoLocaleCode(locale), {}]));
282
+ const menus = Object.fromEntries(locales.map((locale) => [hugoLocaleCode(locale), {}]));
265
283
 
266
284
  return { ...runtimeContext, helper, localized: enhancedLocalized, i18n, menus };
267
285
  },
@@ -289,12 +307,12 @@ export default (args) => {
289
307
  const type = getEntryType(transformContext);
290
308
 
291
309
  if (type === TYPE_CONTENT) {
292
- return options.translationStrategy === STRATEGY_FILENAME ? '' : locale.code;
310
+ return options.translationStrategy === STRATEGY_FILENAME ? '' : hugoLocaleCode(locale);
293
311
  }
294
312
 
295
313
  return options.translationStrategy === STRATEGY_FILENAME
296
314
  ? path.join('../data', contentTypeId)
297
- : path.join('../data', locale.code, contentTypeId);
315
+ : path.join('../data', hugoLocaleCode(locale), contentTypeId);
298
316
  },
299
317
 
300
318
  /**
@@ -323,13 +341,13 @@ export default (args) => {
323
341
 
324
342
  if (homeId && entry?.sys?.id === homeId) {
325
343
  return options.translationStrategy === STRATEGY_FILENAME
326
- ? `/_index.${locale.code}.md`
344
+ ? `/_index.${hugoLocaleCode(locale)}.md`
327
345
  : `/_index.md`;
328
346
  }
329
347
 
330
348
  if (contentTypeId === options.typeIdSettings) {
331
349
  return options.translationStrategy === STRATEGY_FILENAME
332
- ? `../settings.${locale.code}.yaml`
350
+ ? `../settings.${hugoLocaleCode(locale)}.yaml`
333
351
  : '../settings.yaml';
334
352
  }
335
353
 
@@ -340,7 +358,7 @@ export default (args) => {
340
358
  entryMap: collectEntryMap,
341
359
  });
342
360
  return options.translationStrategy === STRATEGY_FILENAME
343
- ? path.join(...(slugs || []).filter((v) => v), `_index.${locale.code}.md`)
361
+ ? path.join(...(slugs || []).filter((v) => v), `_index.${hugoLocaleCode(locale)}.md`)
344
362
  : path.join(...(slugs || []).filter((v) => v), `_index.md`);
345
363
  }
346
364
 
@@ -354,7 +372,9 @@ export default (args) => {
354
372
  return options.translationStrategy === STRATEGY_FILENAME
355
373
  ? path.join(
356
374
  ...(slugs || []).filter((v) => v),
357
- `${collectEntry?.fields?.[options.fieldIdSlug] ?? 'unknown'}.${locale.code}.md`
375
+ `${collectEntry?.fields?.[options.fieldIdSlug] ?? 'unknown'}.${hugoLocaleCode(
376
+ locale
377
+ )}.md`
358
378
  )
359
379
  : path.join(
360
380
  ...(slugs || []).filter((v) => v),
@@ -363,7 +383,7 @@ export default (args) => {
363
383
  }
364
384
 
365
385
  return options.translationStrategy === STRATEGY_FILENAME
366
- ? `${id}.${locale.code}.yaml`
386
+ ? `${id}.${hugoLocaleCode(locale)}.yaml`
367
387
  : `${id}.yaml`;
368
388
  },
369
389
 
@@ -378,7 +398,7 @@ export default (args) => {
378
398
  const { key, other, one } = content;
379
399
  const translations = one ? { one, other } : { other };
380
400
 
381
- runtimeContext.i18n[locale.code][key] = translations;
401
+ runtimeContext.i18n[hugoLocaleCode(locale)][key] = translations;
382
402
 
383
403
  // Dont't write i-18n objects to the content folder
384
404
  return undefined;
@@ -390,7 +410,7 @@ export default (args) => {
390
410
  const { name = 'main' } = entry.fields;
391
411
  const menu = await buildMenu(transformContext, options.menuDepth);
392
412
 
393
- runtimeContext.menus[locale.code][name] = menu;
413
+ runtimeContext.menus[hugoLocaleCode(locale)][name] = menu;
394
414
  }
395
415
 
396
416
  if (type === TYPE_CONTENT) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jungvonmatt/cssg-plugin-hugo",
3
- "version": "1.4.9",
3
+ "version": "1.4.12",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "typings": "./index.d.ts",
@@ -30,5 +30,5 @@
30
30
  "fs-extra": "^10.0.0",
31
31
  "micromatch": "^4.0.4"
32
32
  },
33
- "gitHead": "17ccdcf1aedc0eea54740aa71279e5bd1cb77699"
33
+ "gitHead": "c8949e1d9836e6b1b9310c54e85c66da9e0169f9"
34
34
  }