New feature: Pagination
The blog index now has a pagination feature that allows to break up large collections into multiple pages. Paginated route names should use the same [bracket] syntax as a standard dynamic route. For instance, the file name /blog/[page].astro will generate routes for /blog/1, /blog/2, etc, where [page] is the generated page number. Refer to Astro's documentation on Pagination for more information.
- Upgraded Astro packages
- 119cc5fa2a2d4289d5905f6107fb426315e6f46b - Add the
Paginate.astro
andpaginateButton.astro
components - 7a6b2ae7a59dffe4c96abcdf8f161efea8d0c631 -
blog.astro
is gone, and we now useroutes/blog/[...page].astro
to hold the pagination routing logic
// blog/[...page].astro
- const locale = getLocale();
- const posts = await getCollection("blog", ({ id }) => {
- return id.startsWith(locale);
- });
- posts.sort(
- (a, b) => new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf(),
-);
+ import type { GetStaticPaths, Page } from "astro";
+ import type { CollectionEntry } from "astro:content";
+ import { collectionFilters } from "@astrolicious/i18n/content-collections";
+ import { getLocalePlaceholder } from "i18n:astro";
+ import Pagination from "@components/TemplateComponents/Pagination.astro";
+
+ export const getStaticPaths = (async ({ paginate }) => {
+ const locale = getLocalePlaceholder();
+ const posts = await getCollection("blog", (post: CollectionEntry<"blog">) =>
+ collectionFilters.byLocale(post, { locale })
+ );
+
+ const sortedPosts = posts.sort(
+ (a, b) => new Date(b.data.date).valueOf() - new Date(a.data.date).valueOf(),
+ );
+
+ // paginates with options - https://docs.astro.build/en/reference/api-reference/#paginate
+ return paginate(sortedPosts, {
+ pageSize: 3,
+ });
+ }) satisfies GetStaticPaths;
+
+ const { page } = Astro.props as { page: Page };
- 7a6b2ae7a59dffe4c96abcdf8f161efea8d0c631 - Add translations strings and t functions for pagination buttons
- 383a919117cc64bf9a626c496979e446d1533482 - Add extra blog posts to test the pagination system
- #20 Feature: adds support for localized routes. For example, we are on /blog/third-post-in-english and switch language to fr. We will now correctly navigate to /fr/blog/troisieme-article-en-francais
- 76f8e00 - update
config.astro.mjs
- 720afe6 - renamed [page] to [slug] and modified he getStaticpaths() script to use dynamicParams and localized routes
- acd2672 - add
defaultLocaleVersion
key and renamed markdown files for localization - acd2672 - add
defaultLocaleVersion: reference("blog").optional(),
to your blog schema insrc/content.config.ts
- cd405a8 - using getLocalePath() instead of now deleted slugify() utility function
- 8a2e69d - delete trailing slashes to enforce proper routing
- [3cc3d2f](renamed and changed location of the blog page) - the blog index page is now named
blog.astro
and lives in thepages
folder (from/blog/inddex.astro
)
- Fix: changes file path to use alias instead of absolute path
In blog markdown files, the images were not pulled from the right location. Using alias path
@assets
makes sure images are pulled from src.image: "@assets/images/blog/blog-cover.jpg"
- Astro has been upgraded to v5.0
- Upgrade Astro and its dependencies
- Run
npx @astrojs/upgrade
in your terminal - At the yellow warning, choose “Yes” to continue
- Run
- Breaking change: Renamed: component
📢 Reference: https://docs.astro.build/en/guides/upgrade-to/v5/#renamed-viewtransitions--component-
In
BaseLayout.astro
, replace all occurrences of theViewTransitions
import and component withClientRouter
// BaseLayout.astro - import { ViewTransitions } from 'astro:transitions'; + import { ClientRouter } from 'astro:transitions'; <html> <head> ... - <ViewTransitions /> + <ClientRouter /> </head> </html>
-
-
Breaking Change: Content Collections
📢 Reference: https://docs.astro.build/en/guides/upgrade-to/v5/#updating-existing-collections-
Move the content config file. This file no longer lives within the
src/content/
folder. This file should now exist atsrc/content.config.ts
. -
Edit the collection definition. Your updated collection requires a
loader
which indicates both a folder for the location of your collection (base
) and apattern
defining the collection entry filenames and extensions to match.// src/content.config.ts + import { glob } from 'astro/loaders'; // type: 'content', loader: glob({ pattern: '**/[^_]*.{md,mdx}', base: "./src/content/blog" }),
-
Change references from
slug
toid
. Content layer collections do not have a reservedslug
field. Instead, all updated collections will have anid
.For example:
// src/pages/blog/[...post].astro export async function getStaticPaths() { const posts = await getCollection("blog"); return posts.map((entry) => ({ // params: { post: entry.slug }, params: { post: entry.id }, props: { post: entry }, })); }
📢
CTRL+SHIFT+F
and check for any traces of.slug
. There shouldn’t be any more. -
Switch to the new
render()
function. Entries no longer have arender()
method. Instead, import therender()
function fromastro:content
.// src/pages/blog/[...post].astro import { getCollection, render } from 'astro:content'; // const { Content } = await page.render(); const { Content } = await render(post);
📢 Running into
Module '"astro:content"' has no exported member 'render'
? => Restart the dev server -
Repeat for every content collection you may have added.
-
-
Breaking change: TypeScript configuration
📢 Reference: https://docs.astro.build/en/guides/upgrade-to/v5/#changed-typescript-configuration- Add the following
include
andexclude
properties to your existingtsconfig.json
:
{ "extends": "astro/tsconfigs/base", "include": [".astro/types.d.ts", "**/*"], "exclude": ["dist"] }
- Add the following
- Ensure that the other packages you may have added are up-to-date and compatible with Astro v5
- Please refer to the official Upgrade to v5 guide if you run into any issues.
- Added CHANGELOG.md to keep track of patch changes and setup instructions
-
#17
8a346bb
Thanks @Masoud-M! - Fixes meta tag title to make it check for any language in the config.- Adds utility functions in utils.ts
//utils.ts
export function trimArrSlashes(arr: string[]) {
return arr.map((str) => str.replace(/^\/+|\/+$/g, ""));
}
export function trimStringSlashes(arr: string) {
return arr.replace(/^\/+|\/+$/g, "");
}
- Adds support for checking any language to create the meta title
//BaseLayout.astro
---
+ import { getHtmlAttrs, getLocales, t } from "i18n:astro";
+ import { trimArrSlashes, trimStringSlashes } from "@utils/utils";
+ const locales = getLocales();
+ // Trimming "/" from the beginning and end to handle URLs with or without trailing slashes.
+ const trimmedLocales = trimArrSlashes(locales);
+ const trimmedPathname = trimStringSlashes(Astro.url.pathname);
+ const isLandingPage = Astro.url.pathname === "/" || trimmedLocales.includes(trimmedPathname);
---
- {Astro.url.pathname === "/" ? (`${ title }
+ {isLandingPage ? (`${ title }
- Initial release of Advanced Astro v4 with i18n support.