@c-time/frelio-data-json-generator 1.4.4 → 1.4.6

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/cli.js CHANGED
@@ -728,6 +728,49 @@ function getValueByKey2(key, content, currentData) {
728
728
  return value;
729
729
  }
730
730
 
731
+ // src/recipe/navigation-resolver.ts
732
+ function resolveNavigation(navigation, current, allContents, detailOutputPath) {
733
+ const filtered = applyFilters(allContents, navigation.filters);
734
+ const sorted = applySort(filtered, navigation.sort);
735
+ const idx = sorted.findIndex((c) => c.contentId === current.contentId);
736
+ const toItem = (c) => c ? buildNavigationItem(c, navigation.fields, detailOutputPath) : null;
737
+ return {
738
+ // 現在コンテンツが絞り込み外(idx === -1)の場合、prev/next は null
739
+ prev: idx > 0 ? toItem(sorted[idx - 1]) : null,
740
+ next: idx >= 0 && idx < sorted.length - 1 ? toItem(sorted[idx + 1]) : null,
741
+ first: toItem(sorted[0]),
742
+ last: toItem(sorted[sorted.length - 1])
743
+ };
744
+ }
745
+ function buildNavigationItem(content, fields, detailOutputPath) {
746
+ const item = {
747
+ contentId: content.contentId,
748
+ slug: content.slug,
749
+ title: content.title,
750
+ href: computeHref(detailOutputPath, content)
751
+ };
752
+ if (fields === null || fields === void 0) {
753
+ for (const [key, value] of Object.entries(content.data)) {
754
+ if (!(key in item)) {
755
+ item[key] = value;
756
+ }
757
+ }
758
+ } else {
759
+ for (const key of fields) {
760
+ if (key in content.data) {
761
+ item[key] = content.data[key];
762
+ }
763
+ }
764
+ }
765
+ return item;
766
+ }
767
+ function computeHref(detailOutputPath, content) {
768
+ const resolved = sanitizePath(resolveOutputPath(detailOutputPath, content));
769
+ let href = "/" + toHtmlOutputPath(resolved);
770
+ href = href.replace(/\/index\.html$/, "/");
771
+ return href;
772
+ }
773
+
731
774
  // src/recipe/detail-processor.ts
732
775
  async function processDetailRecipes(contentTypeId, recipes, targets, context) {
733
776
  const outputs = [];
@@ -746,7 +789,7 @@ async function processDetailRecipes(contentTypeId, recipes, targets, context) {
746
789
  continue;
747
790
  }
748
791
  try {
749
- const output = await processDetailContent(recipe, content, context);
792
+ const output = await processDetailContent(recipe, content, contents, context);
750
793
  if (output) {
751
794
  outputs.push(output);
752
795
  }
@@ -762,7 +805,7 @@ async function processDetailRecipes(contentTypeId, recipes, targets, context) {
762
805
  }
763
806
  return outputs;
764
807
  }
765
- async function processDetailContent(recipe, content, context) {
808
+ async function processDetailContent(recipe, content, allContents, context) {
766
809
  const outputPath = sanitizePath(resolveOutputPath(recipe.outputPath, content));
767
810
  const pathError = validateOutputPath(outputPath);
768
811
  if (pathError) {
@@ -787,6 +830,13 @@ async function processDetailContent(recipe, content, context) {
787
830
  if (recipe.customFields) {
788
831
  data = await applyCustomFields(data, recipe.customFields, content, context);
789
832
  }
833
+ if (recipe.navigation) {
834
+ const nav = resolveNavigation(recipe.navigation, content, allContents, recipe.outputPath);
835
+ data.prev = nav.prev;
836
+ data.next = nav.next;
837
+ data.first = nav.first;
838
+ data.last = nav.last;
839
+ }
790
840
  const dataJson = {
791
841
  type: "update",
792
842
  template: recipe.templatePath,