Skip to content

Commit

Permalink
Merge pull request #4 from zapal-tech/feature/update-collections
Browse files Browse the repository at this point in the history
Update collections
  • Loading branch information
BohdanK-W32 authored Oct 26, 2023
2 parents 25a8133 + 1317c54 commit d91f400
Show file tree
Hide file tree
Showing 19 changed files with 550 additions and 254 deletions.
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"^(^types$)|(^types/(.*)$)$",
"^(^assets$)|(^assets/(.*)$)$",
"^(^locales$)|(^locales/(.*)$)$",
"^i18n$",
"^(^components$)|(^components/(.*)$)$",
"^(^collections$)|(^collections/(.*)$)$",
"^(^globals$)|(^globals/(.*)$)$",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zapal/website-cms",
"description": "Zapal's website CMS",
"version": "1.2.4",
"version": "1.2.5",
"main": "dist/server.js",
"license": "MIT",
"scripts": {
Expand Down
22 changes: 20 additions & 2 deletions src/collections/Projects.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import payload from 'payload';
import { CollectionConfig } from 'payload/types';

import { orderField } from 'fields/order';
import { slugField } from 'fields/slug';

import { generalGroup } from 'utils/groups';
import { projectsGroup } from 'utils/groups';

import ProjectImages from './media/ProjectImages';

Expand All @@ -22,14 +23,31 @@ const Projects: CollectionConfig = {
admin: {
useAsTitle: 'preview.name',
defaultColumns: ['order', 'preview.name'],
group: generalGroup,
group: projectsGroup,
},
versions: {
drafts: {
autosave: true,
},
maxPerDoc: 5,
},
endpoints: [
{
path: '/slug/:slug',
method: 'get',
handler: async (req, res) => {
const data = await payload.find({
collection: 'projects',
where: { slug: { equals: req.params.slug } },
limit: 1,
});

if (data.docs.length) return res.status(200).send(data.docs[0]);

res.status(404).send({ error: 'Not found' });
},
},
],
fields: [
{
type: 'tabs',
Expand Down
103 changes: 87 additions & 16 deletions src/collections/blog/Blog.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import payload from 'payload';
import { CollectionConfig } from 'payload/types';

import BlogCoverImages from 'collections/media/BlogCoverImages';

import { richTextField } from 'fields/richText';
import { slugField } from 'fields/slug';

Expand All @@ -24,6 +27,29 @@ const Blog: CollectionConfig = {
useAsTitle: 'content.title',
group: blogGroup,
},
versions: {
drafts: {
autosave: true,
},
maxPerDoc: 5,
},
endpoints: [
{
path: '/slug/:slug',
method: 'get',
handler: async (req, res) => {
const data = await payload.find({
collection: 'blog-posts',
where: { slug: { equals: req.params.slug } },
limit: 1,
});

if (data.docs.length) return res.status(200).send(data.docs[0]);

res.status(404).send({ error: 'Not found' });
},
},
],
fields: [
{
type: 'tabs',
Expand All @@ -42,32 +68,77 @@ const Blog: CollectionConfig = {
en: 'Title',
ua: 'Заголовок',
},
required: true,
},
{
name: 'tags',
type: 'textarea',
name: 'description',
label: {
en: 'Tags',
ua: 'Теги',
en: 'Description',
ua: 'Опис',
},
type: 'relationship',
relationTo: Tags.slug,
hasMany: true,
required: true,
},
{
name: 'author',
type: 'row',
fields: [
{
name: 'tags',
label: {
en: 'Tags',
ua: 'Теги',
},
type: 'relationship',
relationTo: Tags.slug,
hasMany: true,
required: true,
},
{
name: 'author',
label: {
en: 'Author',
ua: 'Автор',
},
type: 'relationship',
relationTo: Authors.slug,
hasMany: false,
required: true,
},
],
},
{
type: 'upload',
name: 'landscape',
relationTo: BlogCoverImages.slug,
label: {
en: 'Author',
ua: 'Автор',
},
admin: {
position: 'sidebar',
en: 'Cover (shown on devices with landscape orientation)',
ua: 'Обкладинка (відображається на пристроях з альбомною орієнтацією)',
},
type: 'relationship',
relationTo: Authors.slug,
hasMany: false,
required: true,
},
// {
// type: 'group',
// name: 'cover',
// fields: [
// {
// type: 'upload',
// name: 'landscape',
// relationTo: BlogCoverImages.slug,
// label: {
// en: 'Cover (shown on devices with landscape orientation)',
// ua: 'Обкладинка (відображається на пристроях з альбомною орієнтацією)',
// },
// },
// {
// type: 'upload',
// name: 'portrait',
// relationTo: BlogCoverImages.slug,
// label: {
// en: 'Cover (shown on devices with portrait orientation)',
// ua: 'Обкладинка (відображається на пристроях з портретною орієнтацією)',
// },
// },
// ],
// },
richTextField({ name: 'content' }),
],
},
Expand Down
22 changes: 22 additions & 0 deletions src/collections/media/BlogAssets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CollectionConfig } from 'payload/types';

import { publicUploadCollectionWithoutApiAccess } from 'utils/access';
import { blogGroup } from 'utils/groups';

const BlogAssets: CollectionConfig = {
slug: 'blog-assets',
labels: {
singular: { en: 'Blog asset', ua: 'Файл блогу' },
plural: { en: 'Blog assets', ua: 'Файли блогу' },
},
upload: true,
access: {
read: publicUploadCollectionWithoutApiAccess,
},
admin: {
group: blogGroup,
},
fields: [],
};

export default BlogAssets;
50 changes: 50 additions & 0 deletions src/collections/media/BlogCoverImages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { CollectionConfig } from 'payload/types';

import { altField } from 'fields/alt';

import { publicUploadCollectionWithoutApiAccess } from 'utils/access';
import { blogGroup } from 'utils/groups';
import { defaultPhotoMimeTypes } from 'utils/mimeTypes';

const BlogCoverImages: CollectionConfig = {
slug: 'blog-cover-images',
labels: {
singular: { en: 'Blog cover image', ua: 'Мета фото (блог)' },
plural: { en: 'Blog cover images', ua: 'Мета фото (блог)' },
},
upload: {
formatOptions: { format: 'webp', options: { lossless: true } },
mimeTypes: defaultPhotoMimeTypes,
imageSizes: [
{
name: '700',
width: 700,
formatOptions: { format: 'webp', options: { quality: 85 } },
},
{
name: '800',
width: 800,
formatOptions: { format: 'webp', options: { quality: 85 } },
},
{
name: '1200',
width: 1200,
formatOptions: { format: 'webp', options: { quality: 85 } },
},
{
name: '1600',
width: 1600,
formatOptions: { format: 'webp', options: { quality: 85 } },
},
],
},
access: {
read: publicUploadCollectionWithoutApiAccess,
},
admin: {
group: blogGroup,
},
fields: [altField()],
};

export default BlogCoverImages;
29 changes: 0 additions & 29 deletions src/collections/media/BlogMetaImages.ts

This file was deleted.

32 changes: 32 additions & 0 deletions src/collections/media/OpenGraphImages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { CollectionConfig } from 'payload/types';

import { publicUploadCollectionWithoutApiAccess } from 'utils/access';
import { mediaGroup } from 'utils/groups';

const OpenGraphImages: CollectionConfig = {
slug: 'open-graph-images',
labels: {
singular: { en: 'Open Graph image', ua: 'Open Graph зображення' },
plural: { en: 'Open Graph images', ua: 'Open Graph зображення' },
},
upload: {
resizeOptions: {
width: 1200,
},
formatOptions: { format: 'webp', options: { quality: 80 } },
mimeTypes: ['image/webp', 'image/jpeg', 'image/png', 'image/svg+xml'],
},
access: {
read: publicUploadCollectionWithoutApiAccess,
},
admin: {
description: {
en: '1200x630 preview image for the link',
ua: '1200x630 зображення попереднього перегляду посилання',
},
group: mediaGroup,
},
fields: [],
};

export default OpenGraphImages;
12 changes: 5 additions & 7 deletions src/collections/media/ProjectAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ import { CollectionConfig } from 'payload/types';
import { altField } from 'fields/alt';

import { publicUploadCollectionWithoutApiAccess } from 'utils/access';
import { mediaGroup } from 'utils/groups';
import { projectsGroup } from 'utils/groups';

const ProjectAssets: CollectionConfig = {
slug: 'project-assets',
labels: {
singular: { en: 'Project Asset', ua: 'Дані проєкту' },
plural: { en: 'Project Assets', ua: 'Дані проєкту' },
},
upload: {
mimeTypes: ['image/webp', 'image/jpeg', 'image/png', 'image/svg+xml'],
singular: { en: 'Project Asset', ua: 'Файл проєкту' },
plural: { en: 'Project Assets', ua: 'Файли проєктів' },
},
upload: true,
access: {
read: publicUploadCollectionWithoutApiAccess,
},
admin: {
group: mediaGroup,
group: projectsGroup,
},
fields: [altField()],
};
Expand Down
4 changes: 2 additions & 2 deletions src/collections/media/ProjectImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CollectionConfig } from 'payload/types';
import { altField } from 'fields/alt';

import { publicUploadCollectionWithoutApiAccess } from 'utils/access';
import { mediaGroup } from 'utils/groups';
import { projectsGroup } from 'utils/groups';
import { defaultPhotoMimeTypes } from 'utils/mimeTypes';

const ProjectImages: CollectionConfig = {
Expand Down Expand Up @@ -50,7 +50,7 @@ const ProjectImages: CollectionConfig = {
read: publicUploadCollectionWithoutApiAccess,
},
admin: {
group: mediaGroup,
group: projectsGroup,
description: {
en: 'All project images need to be 5:4 aspect ratio',
ua: 'Всі зображення повинні бути у співвідношенні сторін 5:4',
Expand Down
1 change: 1 addition & 0 deletions src/fields/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export const urlField = (data?: Partial<Omit<TextField, 'type'>>): TextField =>
ua: 'Посилання',
},
validate: validateUrl,
required: false,
...data,
});
Loading

0 comments on commit d91f400

Please sign in to comment.