feature: pinned blog posts
This commit is contained in:
parent
b099197839
commit
9afd2726b2
6 changed files with 27673 additions and 2 deletions
|
|
@ -38,6 +38,19 @@ export const Blog: CollectionConfig = {
|
|||
de: 'Titel',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'pinned',
|
||||
type: 'checkbox',
|
||||
required: true,
|
||||
defaultValue: false,
|
||||
label: {
|
||||
de: 'Angepinnt',
|
||||
},
|
||||
admin: {
|
||||
position: 'sidebar',
|
||||
description: 'Angepinnte Beiträge werden im Blog und auf der Startseite zuerst angezeigt.',
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'tabs',
|
||||
tabs: [
|
||||
|
|
@ -117,8 +130,10 @@ export const Blog: CollectionConfig = {
|
|||
],
|
||||
},
|
||||
],
|
||||
defaultSort: ['-pinned', '-createdAt'],
|
||||
admin: {
|
||||
useAsTitle: 'title',
|
||||
defaultColumns: ['title', 'pinned', 'updatedAt'],
|
||||
hidden: hide,
|
||||
livePreview: {
|
||||
url: ({ data }) => `/api/draft?url=/blog/${data.id}`,
|
||||
|
|
|
|||
|
|
@ -59,11 +59,12 @@ export const fetchBlogPosts = async (displayOnFrontpage: boolean) => {
|
|||
const payload = await getPayload({ config })
|
||||
return payload.find({
|
||||
collection: 'blog',
|
||||
sort: '-date',
|
||||
sort: ['-pinned', '-createdAt'],
|
||||
select: {
|
||||
title: true,
|
||||
date: true,
|
||||
photo: true,
|
||||
pinned: true,
|
||||
content: displayOnFrontpage ? undefined : true,
|
||||
},
|
||||
where: query,
|
||||
|
|
|
|||
27625
src/migrations/20260716_113205_add_blog_pinned.json
Normal file
27625
src/migrations/20260716_113205_add_blog_pinned.json
Normal file
File diff suppressed because it is too large
Load diff
19
src/migrations/20260716_113205_add_blog_pinned.ts
Normal file
19
src/migrations/20260716_113205_add_blog_pinned.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { MigrateUpArgs, MigrateDownArgs, sql } from '@payloadcms/db-postgres'
|
||||
|
||||
export async function up({ db, payload, req }: MigrateUpArgs): Promise<void> {
|
||||
await db.execute(sql`
|
||||
ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2026-07-19T11:32:04.857Z';
|
||||
ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2026-07-19T11:32:05.134Z';
|
||||
ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2026-08-15T11:32:05.193Z';
|
||||
ALTER TABLE "blog" ADD COLUMN "pinned" boolean DEFAULT false;
|
||||
ALTER TABLE "_blog_v" ADD COLUMN "version_pinned" boolean DEFAULT false;`)
|
||||
}
|
||||
|
||||
export async function down({ db, payload, req }: MigrateDownArgs): Promise<void> {
|
||||
await db.execute(sql`
|
||||
ALTER TABLE "announcement" ALTER COLUMN "date" SET DEFAULT '2026-07-19T09:00:32.028Z';
|
||||
ALTER TABLE "calendar" ALTER COLUMN "date" SET DEFAULT '2026-07-19T09:00:32.325Z';
|
||||
ALTER TABLE "classifieds" ALTER COLUMN "until" SET DEFAULT '2026-08-15T09:00:32.384Z';
|
||||
ALTER TABLE "blog" DROP COLUMN "pinned";
|
||||
ALTER TABLE "_blog_v" DROP COLUMN "version_pinned";`)
|
||||
}
|
||||
|
|
@ -52,6 +52,7 @@ import * as migration_20260609_113259_parish_gallery_caption from './20260609_11
|
|||
import * as migration_20260611_072650_add_contact_person_to_group from './20260611_072650_add_contact_person_to_group';
|
||||
import * as migration_20260611_084920_add_image_with_text_block from './20260611_084920_add_image_with_text_block';
|
||||
import * as migration_20260716_090032_add_user_parish_page_assignments from './20260716_090032_add_user_parish_page_assignments';
|
||||
import * as migration_20260716_113205_add_blog_pinned from './20260716_113205_add_blog_pinned';
|
||||
|
||||
export const migrations = [
|
||||
{
|
||||
|
|
@ -322,6 +323,11 @@ export const migrations = [
|
|||
{
|
||||
up: migration_20260716_090032_add_user_parish_page_assignments.up,
|
||||
down: migration_20260716_090032_add_user_parish_page_assignments.down,
|
||||
name: '20260716_090032_add_user_parish_page_assignments'
|
||||
name: '20260716_090032_add_user_parish_page_assignments',
|
||||
},
|
||||
{
|
||||
up: migration_20260716_113205_add_blog_pinned.up,
|
||||
down: migration_20260716_113205_add_blog_pinned.down,
|
||||
name: '20260716_113205_add_blog_pinned'
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1068,6 +1068,10 @@ export interface Blog {
|
|||
id: string;
|
||||
photo?: (string | null) | Media;
|
||||
title: string;
|
||||
/**
|
||||
* Angepinnte Beiträge werden im Blog und auf der Startseite zuerst angezeigt.
|
||||
*/
|
||||
pinned: boolean;
|
||||
content: {
|
||||
excerpt: string;
|
||||
content: (
|
||||
|
|
@ -1886,6 +1890,7 @@ export interface CalendarSelect<T extends boolean = true> {
|
|||
export interface BlogSelect<T extends boolean = true> {
|
||||
photo?: T;
|
||||
title?: T;
|
||||
pinned?: T;
|
||||
content?:
|
||||
| T
|
||||
| {
|
||||
|
|
|
|||
Loading…
Reference in a new issue