Skip to content

Commit

Permalink
Add generic landing page content type
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Richard committed Aug 25, 2023
1 parent 3a2df9f commit 1a28c7b
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cms/lib/desk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
BiMailSend,
BiCodeCurly,
} from 'react-icons/bi';
import { RiTodoLine } from 'react-icons/ri';
import { map } from 'rxjs/operators';

import { AiOutlineFileSearch } from 'react-icons/ai';
Expand Down Expand Up @@ -159,6 +160,14 @@ export const deskStructure = (
.title('Newsletter')
.icon(BiMailSend)
.child(buildStandaloneList('newsletter', 'Newsletter', S)),
S.listItem()
.title('Landing Pages')
.icon(RiTodoLine)
.child(
S.documentTypeList('landing').filter(
'_type == "landing" && !defined(__i18n_base)',
),
),
S.listItem()
.title('Powerful PWAs')
.icon(IoLogoPwa)
Expand Down
4 changes: 4 additions & 0 deletions cms/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import themeSubschema from '$subschema/theme';
import appSubschema from '$subschema/app';
import resourcesSubschema from '$subschema/resources';
import homepageCardSchema from '$subschema/homepage-card';
import bannerSubschema from '$subschema/banner';

// Schemas
import tag from './tag';
Expand All @@ -64,6 +65,7 @@ import newsletter from './newsletter';
import stories from './stories';
import cookies from './cookies';
import pwas from './pwas';
import landing from './landing';

export const schemaTypes = [
// Schemas
Expand All @@ -81,6 +83,7 @@ export const schemaTypes = [
stories,
cookies,
pwas,
landing,

// Fields
fullBlockField,
Expand Down Expand Up @@ -117,4 +120,5 @@ export const schemaTypes = [
appSubschema,
resourcesSubschema,
homepageCardSchema,
bannerSubschema,
];
107 changes: 107 additions & 0 deletions cms/schemas/landing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* Copyright 2022 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { defineField, defineType } from 'sanity';
import { isL10n } from '$lib/validators/i18n';

export default defineType({
name: 'landing',
title: 'Landing Page',
type: 'document',
i18n: true,
groups: [
{
name: 'content',
title: 'Content',
default: true,
},
{
name: 'publishing',
title: 'Publishing',
},
{
name: 'promotion',
title: 'Promotion',
},
{
name: 'seo_social',
title: 'SEO & Social',
},
],
fields: [
defineField({
name: 'title',
title: 'Title',
type: 'title',
group: ['content', 'seo_social'],
}),
defineField({
name: 'slug',
title: 'Slug',
type: 'l10n-slug',
group: ['seo_social'],
}),
defineField({
name: 'description',
title: 'Description',
type: 'description',
group: ['seo_social'],
}),
defineField({
name: 'category',
title: 'Category',
type: 'reference',
to: { type: 'tag' },
validation: (Rule) => Rule.required(),
group: ['content'],
options: {
disableNew: true,
filter: 'is_post_category == true',
},
readOnly: isL10n,
hidden: isL10n,
}),

defineField({
name: 'banner',
title: 'Banner',
type: 'banner',
group: ['content'],
validation: (Rule) => Rule.required(),
readOnly: isL10n,
hidden: isL10n,
}),

defineField({
name: 'body',
title: 'Body',
group: 'content',
type: 'full-block',
validation: (Rule) => Rule.required(),
}),
],

preview: {
select: {
title: 'title',
media: 'banner.narrow',
},
prepare(selection) {
return {
...selection,
};
},
},
});
20 changes: 20 additions & 0 deletions cms/schemas/subschema/banner.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { defineType, defineField } from 'sanity';

export default defineType({
name: 'banner',
title: 'Banner media',
description: 'Banner background images',
type: 'object',
fields: [
defineField({
name: 'wide',
title: 'Wide banner image',
type: 'image',
}),
defineField({
name: 'narrow',
title: 'Narrow banner image',
type: 'image',
}),
],
});

0 comments on commit 1a28c7b

Please sign in to comment.