aboutsummaryrefslogtreecommitdiffstats
path: root/src/pages
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-17 17:27:54 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-18 19:30:47 +0100
commit6ab9635a22d69186c8a24181ad5df7736e288577 (patch)
tree855c74af9a336d9130c40f07fa8d51acb42dc701 /src/pages
parentdcd2a7ab382fece8e0ae2979aad4a180b6a105e1 (diff)
fix: generate an id for each headings in the page main contents
Since #be4d907 the ids was no longer addded to headings in useHeadingsTree hook. It was a bad practice to manipulate the DOM that way. However, I did not move the implementation elsewhere... To fix this, I now use rehype-slug on both markdown contents and html string coming from WordPress. I'm not sure the dynamic imports are really useful here since the table of contents is on almost all pages but Jest was failing with regular import because of ESM. It is the only thing that makes the tests functional again so... However if we want to test the `updateContentTree` function, Jest fails for the same reason. So I decided to not test this function. I've already spend too much time on this issue. Another problem: the ToC on projects page. Currently we use the ref on the body but the page contents are imported dynamically so the hook is executed before the contents are loaded. It makes the ToC empty... We should refactor the pages so we can use the ref directly on the imported contents.
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/blog/page/[number].tsx14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/pages/blog/page/[number].tsx b/src/pages/blog/page/[number].tsx
index 49b5eb4..03b641b 100644
--- a/src/pages/blog/page/[number].tsx
+++ b/src/pages/blog/page/[number].tsx
@@ -39,12 +39,15 @@ import {
getBlogSchema,
getLinksItemData,
getPageLinkFromRawData,
- getPostsList,
getSchemaJson,
getWebPageSchema,
} from '../../../utils/helpers';
import { loadTranslation, type Messages } from '../../../utils/helpers/server';
-import { useBreadcrumb, useRedirection } from '../../../utils/hooks';
+import {
+ useBreadcrumb,
+ usePostsList,
+ useRedirection,
+} from '../../../utils/hooks';
type BlogPageProps = {
articles: EdgesResponse<RawArticle>;
@@ -70,6 +73,11 @@ const BlogPage: NextPageWithLayout<BlogPageProps> = ({
redirectTo: ROUTES.BLOG,
});
+ const { posts } = usePostsList({
+ fallback: [articles],
+ fetcher: getArticles,
+ perPage: CONFIG.postsPerPage,
+ });
const intl = useIntl();
const title = intl.formatMessage({
defaultMessage: 'Blog',
@@ -260,7 +268,7 @@ const BlogPage: NextPageWithLayout<BlogPageProps> = ({
/>,
]}
>
- <PostsList posts={getPostsList([articles])} sortByYear />
+ <PostsList posts={posts ?? []} sortByYear />
<Pagination
aria-label={paginationAriaLabel}
current={pageNumber}