Skip to content

Commit

Permalink
[Sanity] Config cleanup (#3312)
Browse files Browse the repository at this point in the history
* sanity config cleanup

* removed extra const for type

* Update aksel.nav.no/website/sanity/schema/documents/presets/seo.ts

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>

---------

Co-authored-by: Halvor Haugan <83693529+HalvorHaugan@users.noreply.github.com>
  • Loading branch information
KenAJoh and HalvorHaugan authored Nov 6, 2024
1 parent 923fce1 commit 2d669a7
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 106 deletions.
35 changes: 35 additions & 0 deletions aksel.nav.no/website/sanity/logo.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export const AkselLogo = () => (
<svg
width="32"
height="32"
viewBox="0 0 32 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<style>
{`path[data-path="1"] {
fill: #00243a;
}
path[data-path="2"] {
fill: #ffd799;
}
.dark path[data-path="1"] {
fill: #ffd799;
}
.dark path[data-path="2"] {
fill: #00243a;
}
`}
</style>
<path
data-path="1"
d="M0 4C0 1.79086 1.79086 0 4 0H28C30.2091 0 32 1.79086 32 4V28C32 30.2091 30.2091 32 28 32H4C1.79086 32 0 30.2091 0 28V4Z"
/>
<path
data-path="2"
fillRule="evenodd"
clipRule="evenodd"
d="M4.43934 9.93931C4.1476 10.2311 4.00115 10.6131 4.00001 10.9955C3.99885 11.3808 4.14527 11.7666 4.43929 12.0606C5.02505 12.6464 5.9748 12.6465 6.56061 12.0607L11.3112 7.31056C11.7029 6.93797 12.3226 6.94391 12.7071 7.3284L24.6716 19.2929C25.0621 19.6834 25.0621 20.3166 24.6716 20.7071L19.9393 25.4393C19.3536 26.0251 19.3536 26.9748 19.9393 27.5606C20.2083 27.8296 20.5539 27.975 20.9058 27.997C21.3206 28.0231 21.7442 27.8776 22.0611 27.5607L26.8289 22.7929C27.5791 22.0427 28.0005 21.0253 28.0005 19.9644L28.0001 7.99987C28 5.79078 26.2092 4 24.0001 4H12.036C10.9753 4 9.95813 4.42124 9.20803 5.17108C9.19582 5.18298 9.18367 5.19498 9.17157 5.20708L4.43934 9.93931ZM25.0003 15.379L16.6214 7H24.0001C24.5524 7 25.0001 7.4477 25.0001 7.99997L25.0003 15.379ZM14.5607 19.5606C15.1464 18.9749 15.1464 18.0251 14.5607 17.4393C13.9749 16.8535 13.0251 16.8535 12.4393 17.4393L4.43934 25.4393C3.85355 26.0251 3.85355 26.9749 4.43934 27.5606C5.02513 28.1464 5.97487 28.1464 6.56066 27.5606L14.5607 19.5606Z"
/>
</svg>
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,58 @@ import { colorInput } from "@sanity/color-input";
import { nbNOLocale } from "@sanity/locale-nb-no";
import { table } from "@sanity/table";
import { visionTool } from "@sanity/vision";
import React from "react";
import { FieldProps, defineConfig } from "sanity";
import { AuthConfig, defineConfig } from "sanity";
import { media } from "sanity-plugin-media";
import { structureTool } from "sanity/structure";
import { DatabaseIcon, TestFlaskIcon } from "@navikt/aksel-icons";
import { SANITY_API_VERSION, SANITY_PROJECT_ID } from "./config";
import { TestFlaskIcon } from "@navikt/aksel-icons";
import { SANITY_PROJECT_ID } from "./config";
import { AkselLogo } from "./logo";
import { defaultDocumentNode, publicationFlow, structure } from "./plugins";
import { schema } from "./schema";
import { InputWithCounter } from "./schema/custom-components";
import { newDocumentsCreator } from "./util";

export const workspaceConfig = defineConfig([
{
...defaultConfig(),
projectId: SANITY_PROJECT_ID,
title: "Aksel",
description: "Production environment for Aksel",
name: "default",
dataset: "production",
basePath: "/admin/prod",
icon: DatabaseIcon,
auth: authStore("production"),
icon: AkselLogo,
auth: authStore(),
scheduledPublishing: { enabled: false },
schema,
document: {
newDocumentOptions: newDocumentsCreator,
},
plugins: [
structureTool({
title: "Editor",
structure,
defaultDocumentNode,
}),
publicationFlow(),

/* 3rd-party */
table(),
codeInput(),
media(),
visionTool(),
colorInput(),
nbNOLocale(),
],
},
{
...defaultConfig(),
title: "Aksel Dev-miljø",
projectId: SANITY_PROJECT_ID,
title: "Aksel Development",
description: "Development environment for Aksel",
name: "dev",
dataset: "development",
basePath: "/admin/dev",
icon: TestFlaskIcon,
auth: authStore("development"),
},
]);

function defaultConfig() {
return {
projectId: SANITY_PROJECT_ID,
apiVersion: SANITY_API_VERSION,
auth: authStore(),
schema,
scheduledPublishing: { enabled: false },
form: {
components: {
field: (props: FieldProps) => {
const name = props.schemaType?.name;

if (name === "string" && props.schemaType?.options?.maxLength) {
return <InputWithCounter {...props} />;
}

if (name === "text" && props.schemaType?.options?.maxLength) {
return <InputWithCounter {...props} size="large" />;
}
return props.renderDefault(props);
},
},
},
document: {
newDocumentOptions: newDocumentsCreator,
},
Expand All @@ -76,15 +74,13 @@ function defaultConfig() {
colorInput(),
nbNOLocale(),
],
};
}
},
]);

function authStore(dataset: string) {
function authStore(): AuthConfig {
return {
redirectOnSingle: false,
mode: "replace" as const,
projectId: SANITY_PROJECT_ID,
dataset,
mode: "replace",
providers: [
{
name: "saml",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./InputWithCounter";
export * from "./updateInfo";
export * from "./WriteHelp";
12 changes: 4 additions & 8 deletions aksel.nav.no/website/sanity/schema/documents/presets/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ export const ingressField = defineField({
type: "text",
group: "innhold",
rows: 3,
validation: (Rule) =>
Rule.required()
.max(210)
.error("Side må ha en ingress og kortere enn 210 tegn."),
options: {
//@ts-expect-error - maxLength is a custom prop not officially supported
maxLength: 210,
},
validation: (Rule) => [
Rule.required().min(10),
Rule.max(210).warning("Ingress bør være kortere enn 210 tegn."),
],
});
6 changes: 2 additions & 4 deletions aksel.nav.no/website/sanity/schema/documents/presets/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ const BaseSEOPreset = {
title: "OG-description (valgfri)",
description: "Erstatter ingress som OG-description og meta-tag",
rows: 3,
options: {
// @ts-expect-error - maxLength is a custom prop not officially supported
maxLength: 160,
},
validation: (Rule) =>
Rule.max(160).warning("OG-beskrivelse bør være kortere enn 160 tegn."),
}),
{
title: "OG-image",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@ export const titleField = defineField({
type: "string",
group: "innhold",
description: "Bruk en kort og konsis tittel",

validation: (Rule) => [
Rule.required().min(3).error("Sidetittel må være på minst 3 tegn"),
Rule.max(60).error("Sidetittel kan ikke være over 60 tegn"),
Rule.required().min(3).error("Sidetittel må være på minst 3 tegn."),
Rule.max(60).warning("Sidetittel bør ikke være over 60 tegn."),
],
options: {
//@ts-expect-error - maxLength is a custom prop not officially supported
maxLength: 60,
},
});

0 comments on commit 2d669a7

Please sign in to comment.