feat: title links on posts in lists
This commit is contained in:
@@ -15,6 +15,7 @@ export interface HtmlRewriteContext {
|
|||||||
|
|
||||||
export interface TemplatePostEntry {
|
export interface TemplatePostEntry {
|
||||||
id: string;
|
id: string;
|
||||||
|
slug: string;
|
||||||
title: string;
|
title: string;
|
||||||
content: string;
|
content: string;
|
||||||
show_title: boolean;
|
show_title: boolean;
|
||||||
@@ -896,6 +897,7 @@ export class PageRenderer {
|
|||||||
show_separator: false,
|
show_separator: false,
|
||||||
posts: posts.map((post) => ({
|
posts: posts.map((post) => ({
|
||||||
id: post.id,
|
id: post.id,
|
||||||
|
slug: post.slug,
|
||||||
title: post.title,
|
title: post.title,
|
||||||
content: post.content,
|
content: post.content,
|
||||||
show_title: shouldShowListTitle(post),
|
show_title: shouldShowListTitle(post),
|
||||||
@@ -921,6 +923,7 @@ export class PageRenderer {
|
|||||||
|
|
||||||
currentBlock.block.posts.push({
|
currentBlock.block.posts.push({
|
||||||
id: post.id,
|
id: post.id,
|
||||||
|
slug: post.slug,
|
||||||
title: post.title,
|
title: post.title,
|
||||||
content: post.content,
|
content: post.content,
|
||||||
show_title: shouldShowListTitle(post),
|
show_title: shouldShowListTitle(post),
|
||||||
@@ -1074,6 +1077,7 @@ export class PageRenderer {
|
|||||||
menu_items: pageContext.menu_items ?? [],
|
menu_items: pageContext.menu_items ?? [],
|
||||||
post: {
|
post: {
|
||||||
id: renderablePost.id,
|
id: renderablePost.id,
|
||||||
|
slug: renderablePost.slug,
|
||||||
title: renderablePost.title,
|
title: renderablePost.title,
|
||||||
content: renderablePost.content,
|
content: renderablePost.content,
|
||||||
show_title: false,
|
show_title: false,
|
||||||
|
|||||||
@@ -38,7 +38,11 @@
|
|||||||
{% for post in day_block.posts %}
|
{% for post in day_block.posts %}
|
||||||
<div class="post">
|
<div class="post">
|
||||||
{% if post.show_title %}
|
{% if post.show_title %}
|
||||||
<h2 class="post-title">{{ post.title }}</h2>
|
{% assign canonical_post_href = canonical_post_path_by_slug[post.slug] %}
|
||||||
|
{% if canonical_post_href == blank %}
|
||||||
|
{% assign canonical_post_href = '/posts/' | append: post.slug %}
|
||||||
|
{% endif %}
|
||||||
|
<h2 class="post-title"><a href="{{ canonical_post_href }}">{{ post.title }}</a></h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ post.content | markdown: post.id, canonical_post_path_by_slug, canonical_media_path_by_source_path, language }}
|
{{ post.content | markdown: post.id, canonical_post_path_by_slug, canonical_media_path_by_source_path, language }}
|
||||||
</div>
|
</div>
|
||||||
@@ -49,7 +53,11 @@
|
|||||||
{% for post in day_block.posts %}
|
{% for post in day_block.posts %}
|
||||||
<div class="post">
|
<div class="post">
|
||||||
{% if post.show_title %}
|
{% if post.show_title %}
|
||||||
<h2 class="post-title">{{ post.title }}</h2>
|
{% assign canonical_post_href = canonical_post_path_by_slug[post.slug] %}
|
||||||
|
{% if canonical_post_href == blank %}
|
||||||
|
{% assign canonical_post_href = '/posts/' | append: post.slug %}
|
||||||
|
{% endif %}
|
||||||
|
<h2 class="post-title"><a href="{{ canonical_post_href }}">{{ post.title }}</a></h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ post.content | markdown: post.id, canonical_post_path_by_slug, canonical_media_path_by_source_path, language }}
|
{{ post.content | markdown: post.id, canonical_post_path_by_slug, canonical_media_path_by_source_path, language }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -251,6 +251,7 @@ describe('BlogGenerationEngine', () => {
|
|||||||
expect(indexHtml).toContain('href="/"');
|
expect(indexHtml).toContain('href="/"');
|
||||||
expect(indexHtml).toContain('href="/about/"');
|
expect(indexHtml).toContain('href="/about/"');
|
||||||
expect(indexHtml).toContain('href="/category/news/"');
|
expect(indexHtml).toContain('href="/category/news/"');
|
||||||
|
expect(indexHtml).toContain('<h2 class="post-title"><a href="/2025/03/15/hello-world">Hello World</a></h2>');
|
||||||
expect(indexHtml).toContain('class="blog-menu-submenu"');
|
expect(indexHtml).toContain('class="blog-menu-submenu"');
|
||||||
|
|
||||||
const listH1Index = indexHtml.indexOf('<h1 class="archive-heading"');
|
const listH1Index = indexHtml.indexOf('<h1 class="archive-heading"');
|
||||||
|
|||||||
@@ -1017,7 +1017,7 @@ describe('PreviewServer', () => {
|
|||||||
await server.start(0);
|
await server.start(0);
|
||||||
|
|
||||||
const html = await (await fetch(`${server.getBaseUrl()}/`)).text();
|
const html = await (await fetch(`${server.getBaseUrl()}/`)).text();
|
||||||
expect(html).toContain('<h2 class="post-title">Article Title</h2>');
|
expect(html).toContain('<h2 class="post-title"><a href="/2025/02/06/pt-1">Article Title</a></h2>');
|
||||||
expect(html).not.toContain('<h2 class="post-category-title">article</h2>');
|
expect(html).not.toContain('<h2 class="post-category-title">article</h2>');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user