@quartz-community/tag-page 1.0.0 → 1.0.2

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/index.js CHANGED
@@ -271,8 +271,6 @@ function getDate(data) {
271
271
  const dates = data.dates;
272
272
  return dates?.[defaultDateType];
273
273
  }
274
-
275
- // node_modules/@quartz-community/utils/dist/path.js
276
274
  function simplifySlug(fp) {
277
275
  const res = stripSlashes(trimSuffix(fp, "index"), true);
278
276
  return res.length === 0 ? "/" : res;
@@ -2784,6 +2782,19 @@ function i18n(locale) {
2784
2782
  return locales[locale] || en_US_default;
2785
2783
  }
2786
2784
 
2785
+ // src/util/tags.ts
2786
+ function hasChildTags(tag, allTags) {
2787
+ const prefix = `${tag}/`;
2788
+ for (const t2 of allTags) {
2789
+ if (t2.startsWith(prefix)) return true;
2790
+ }
2791
+ return false;
2792
+ }
2793
+ function tagPageSlug(tag, allTags) {
2794
+ if (tag === "index") return "tags/index";
2795
+ return hasChildTags(tag, allTags) ? joinSegments("tags", tag, "index") : joinSegments("tags", tag);
2796
+ }
2797
+
2787
2798
  // src/components/styles/listPage.scss
2788
2799
  var listPage_default = "ul.section-ul {\n list-style: none;\n margin-top: 2em;\n padding-left: 0;\n}\n\nli.section-li {\n margin-bottom: 1em;\n}\nli.section-li > .section {\n display: grid;\n grid-template-columns: fit-content(8em) 3fr 1fr;\n}\n@media all and (max-width: 600px) {\n li.section-li > .section > .tags {\n display: none;\n }\n}\nli.section-li > .section > .desc > h3 > a {\n background-color: transparent;\n}\nli.section-li > .section .meta {\n margin: 0 1em 0 0;\n opacity: 0.6;\n}\n\n.popover .section {\n grid-template-columns: fit-content(8em) 1fr !important;\n}\n.popover .section > .tags {\n display: none;\n}";
2789
2800
 
@@ -2803,12 +2814,13 @@ var TagContent_default = ((opts) => {
2803
2814
  const TagContent = (props) => {
2804
2815
  const { tree, fileData, allFiles, cfg } = props;
2805
2816
  const fd = fileData;
2806
- const slug2 = fd.slug;
2817
+ const slug = fd.slug;
2807
2818
  const locale = cfg?.locale ?? "en-US";
2808
- if (!(slug2?.startsWith("tags/") || slug2 === "tags")) {
2809
- throw new Error(`Component "TagContent" tried to render a non-tag page: ${slug2}`);
2819
+ if (!(slug?.startsWith("tags/") || slug === "tags")) {
2820
+ throw new Error(`Component "TagContent" tried to render a non-tag page: ${slug}`);
2810
2821
  }
2811
- const tag = simplifySlug(slug2.slice("tags/".length));
2822
+ let tag = simplifySlug(slug.slice("tags/".length));
2823
+ if (tag !== "/" && tag.endsWith("/")) tag = tag.slice(0, -1);
2812
2824
  const allPagesWithTag = (t2) => allFiles.filter(isListed).filter(
2813
2825
  (file) => (file.frontmatter?.tags ?? []).flatMap(getAllSegmentPrefixes).includes(t2)
2814
2826
  );
@@ -2841,12 +2853,12 @@ var TagContent_default = ((opts) => {
2841
2853
  sort: options?.sort
2842
2854
  });
2843
2855
  const contentPage = allFiles.find(
2844
- (file) => file.slug === `tags/${t2}`
2856
+ (file) => file.slug === `tags/${t2}` || file.slug === `tags/${t2}/index`
2845
2857
  );
2846
2858
  const root2 = contentPage?.filePath ? contentPage?.htmlAst : void 0;
2847
2859
  const tagDesc = !root2 || root2.children.length === 0 ? contentPage?.description : htmlToJsx(root2);
2848
- const tagListingPage = `/tags/${t2}`;
2849
- const href = resolveRelative(slug2, tagListingPage);
2860
+ const tagListingPage = contentPage?.slug ?? tagPageSlug(t2, tags);
2861
+ const href = resolveRelative(slug, tagListingPage);
2850
2862
  return /* @__PURE__ */ u2("div", { children: [
2851
2863
  /* @__PURE__ */ u2("h2", { children: /* @__PURE__ */ u2("a", { class: "internal tag-link", href, children: t2 }) }),
2852
2864
  tagDesc && /* @__PURE__ */ u2("p", { children: tagDesc }),
@@ -2889,8 +2901,8 @@ var TagContent_default = ((opts) => {
2889
2901
  });
2890
2902
 
2891
2903
  // src/pageType.ts
2892
- var tagMatcher = ({ slug: slug2 }) => {
2893
- return slug2.startsWith("tags/") || slug2 === "tags";
2904
+ var tagMatcher = ({ slug }) => {
2905
+ return slug.startsWith("tags/") || slug === "tags";
2894
2906
  };
2895
2907
  var TagPage = (opts) => ({
2896
2908
  name: "TagPage",
@@ -2905,18 +2917,20 @@ var TagPage = (opts) => ({
2905
2917
  tags.add("index");
2906
2918
  const existingTagSlugs = /* @__PURE__ */ new Set();
2907
2919
  for (const [, file] of content) {
2908
- const slug2 = file.data?.slug;
2909
- if (slug2 && slug2.startsWith("tags/")) {
2910
- existingTagSlugs.add(slug2);
2920
+ const slug = file.data?.slug;
2921
+ if (slug && slug.startsWith("tags/")) {
2922
+ existingTagSlugs.add(slug);
2911
2923
  }
2912
2924
  }
2913
2925
  const virtualPages = [];
2914
2926
  for (const tag of tags) {
2915
- const slug2 = joinSegments("tags", tag);
2916
- if (existingTagSlugs.has(slug2)) continue;
2927
+ const slug = tagPageSlug(tag, tags);
2928
+ if (existingTagSlugs.has(joinSegments("tags", tag)) || existingTagSlugs.has(joinSegments("tags", tag, "index"))) {
2929
+ continue;
2930
+ }
2917
2931
  const title = tag === "index" ? i18n(locale).pages.tagContent.tagIndex : opts?.prefixTags ? `${i18n(locale).pages.tagContent.tag}: ${tag}` : tag;
2918
2932
  virtualPages.push({
2919
- slug: slug2,
2933
+ slug,
2920
2934
  title,
2921
2935
  data: {}
2922
2936
  });