Fix: getAllTags bug when there are more than 15 tags
This commit fixes a bug in the getAllTags function that caused it to not retrieve all tags when there were more than 15 tags. This bug resulted in 404 errors on tag slug pages. fix #99
This commit is contained in:
parent
10bcac444b
commit
15dc9b0719
|
@ -1,13 +1,13 @@
|
||||||
---
|
---
|
||||||
import type { InferGetStaticParamsType, InferGetStaticPropsType } from 'astro';
|
|
||||||
import DefaultPageLayout from "../../layouts/default.astro";
|
|
||||||
import PostPreview from "../../components/PostPreview.astro";
|
|
||||||
import { getAllPosts, getAllTags, getSettings, invariant } from "@matthiesenxyz/astro-ghostcms/api";
|
import { getAllPosts, getAllTags, getSettings, invariant } from "@matthiesenxyz/astro-ghostcms/api";
|
||||||
|
import type { InferGetStaticParamsType, InferGetStaticPropsType } from 'astro';
|
||||||
|
import PostPreview from "../../components/PostPreview.astro";
|
||||||
|
import DefaultPageLayout from "../../layouts/default.astro";
|
||||||
import { getGhostImgPath } from "../../utils";
|
import { getGhostImgPath } from "../../utils";
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const posts = await getAllPosts();
|
const posts = await getAllPosts();
|
||||||
const { tags } = await getAllTags();
|
const tags = await getAllTags();
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
|
|
||||||
return tags.map((tag) => {
|
return tags.map((tag) => {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
---
|
---
|
||||||
import DefaultPageLayout from "../layouts/default.astro";
|
import { getAllTags, getSettings, invariant } from "@matthiesenxyz/astro-ghostcms/api";
|
||||||
import TagCard from "../components/TagCard.astro";
|
import TagCard from "../components/TagCard.astro";
|
||||||
import { getSettings, getAllTags, invariant } from "@matthiesenxyz/astro-ghostcms/api";
|
import DefaultPageLayout from "../layouts/default.astro";
|
||||||
|
|
||||||
|
|
||||||
let title = "All Tags";
|
let title = "All Tags";
|
||||||
let description = "All the tags used so far...";
|
let description = "All the tags used so far...";
|
||||||
|
|
||||||
const { tags } = await getAllTags();
|
const tags = await getAllTags();
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
invariant(settings, "Settings not found");
|
invariant(settings, "Settings not found");
|
||||||
---
|
---
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { TSGhostContentAPI } from "@ts-ghost/content-api";
|
import { TSGhostContentAPI } from "@ts-ghost/content-api";
|
||||||
import type { Page, Post } from "../schemas/api";
|
import type { Page, Post, Tag } from "../schemas/api";
|
||||||
|
|
||||||
// LOAD ENVIRONMENT VARIABLES
|
// LOAD ENVIRONMENT VARIABLES
|
||||||
import { loadEnv } from "vite";
|
import { loadEnv } from "vite";
|
||||||
|
@ -94,17 +94,20 @@ export const getSettings = async () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAllTags = async () => {
|
export const getAllTags = async () => {
|
||||||
const results = await api.tags
|
const tags: Tag[] = [];
|
||||||
.browse()
|
let cursor = await api.tags
|
||||||
|
.browse({
|
||||||
|
limit: 'all'
|
||||||
|
})
|
||||||
.include({ "count.posts": true })
|
.include({ "count.posts": true })
|
||||||
.fetch();
|
.paginate();
|
||||||
if (!results.success) {
|
|
||||||
throw new Error(results.errors.map((e) => e.message).join(", "));
|
if (cursor.current.success) tags.push(...cursor.current.data);
|
||||||
|
while (cursor.next) {
|
||||||
|
cursor = await cursor.next.paginate();
|
||||||
|
if (cursor.current.success) tags.push(...cursor.current.data);
|
||||||
}
|
}
|
||||||
return {
|
return tags;
|
||||||
tags: results.data,
|
|
||||||
meta: results.meta,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getFeaturedPosts = async () => {
|
export const getFeaturedPosts = async () => {
|
||||||
|
|
|
@ -16,7 +16,7 @@ import satoriOG from "../../satori";
|
||||||
export const getStaticPaths: GetStaticPaths = async () => {
|
export const getStaticPaths: GetStaticPaths = async () => {
|
||||||
const result: GetStaticPathsItem[] = [];
|
const result: GetStaticPathsItem[] = [];
|
||||||
const posts = await getAllPosts();
|
const posts = await getAllPosts();
|
||||||
const { tags } = await getAllTags();
|
const tags = await getAllTags();
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
invariant(settings, "Settings are required");
|
invariant(settings, "Settings are required");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue