Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🆕 Add Tutorial content type #768

Merged
merged 48 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
5edaa06
Add DB migration script
May 20, 2024
fcb3f46
Add development dataset switch
Snugug Jun 3, 2024
c5c9e50
Add I/O 2024 theme
Snugug Jun 3, 2024
9047035
Improve borders, especially on the home page
Snugug Jun 4, 2024
15aff31
Add archive build and serve options
Snugug Jun 4, 2024
57132e5
Remove unused codepaths from Sanity
Snugug Jun 4, 2024
2253634
WIP Tutorial content type
Snugug Jun 4, 2024
63541b7
Updated Tutorial schema
Jun 5, 2024
6ea5bb2
Add tutorial microcopy
Jun 12, 2024
2d9a925
Simplify tutorial content type
Jun 12, 2024
6b41b69
Add back and forward direction to generic CTAs
Jun 12, 2024
d6445d0
Add Software component
Jun 12, 2024
2728fee
Update CTA styling if icons are present
Jun 12, 2024
4621a91
Tutorial query and types
Jun 12, 2024
4cae728
Adapt doc layout to include generic content area, not just type conte…
Jun 12, 2024
30f1499
Add tutorial templates
Jun 12, 2024
b389b13
Clean up logging
Jun 13, 2024
deca8f5
Fix CLI build
Snugug Jun 13, 2024
793511f
Merge branch 'feature/tutorial' of github.com:chromeos/chromeos.dev i…
Snugug Jun 13, 2024
9f3a531
Fix Code filename
Jun 17, 2024
8cc56e1
Make cursor pointer for reinforcement
Jun 17, 2024
b85a73b
Fix canvas taking over page on load by only triggering if visible
Jun 17, 2024
1b54cb3
Only include file download/link if on intro
Jun 17, 2024
83d27b2
Fix prerequisite rendering
Jun 17, 2024
ddd33c7
Merge branch 'feature/tutorial' of github.com:chromeos/chromeos.dev i…
Jun 17, 2024
f03dcad
Remove unneeded log
Jun 17, 2024
85bbdf0
Remove broken ESLint rule
Jun 21, 2024
8ea2e2a
Make some Sanity queries reusable, for previews
Jun 21, 2024
36cdbde
Add views path to TSConfig
Jun 21, 2024
1408661
Add dark mode outline
Jun 21, 2024
420a46c
Export TOC title
Jun 21, 2024
0af4e4b
Fix dark mode color
Jun 21, 2024
33f05d1
Migrate preview-able content to Views
Jun 21, 2024
e0e1723
Add Preview route
Jun 21, 2024
0e690a1
Update Preview view to support final implementation
Jun 21, 2024
b3897b0
Include sanity API info for preview
Jun 21, 2024
1755517
Merge branch 'main' into feature/tutorial
Snugug Jun 21, 2024
caade11
Update for sharing overrides
Jun 21, 2024
e62e4bf
Add preview generation log
Jun 21, 2024
2d4e29c
Remove recommended
Jul 1, 2024
af9b7b4
Add Preview Key to env vars
Jul 1, 2024
db3637b
Fix linting
Jul 1, 2024
8e00742
Move slugify to proper dependency
Jul 1, 2024
a9e7cf2
More dependnecies moving up
Jul 1, 2024
bf9ca52
Swap Prism for Shiki
Jul 1, 2024
fa110ad
Update PNPM lock
Jul 1, 2024
bf73a18
Swap preview URL depending on mode, for working against localhost
Jul 1, 2024
f9093f5
Remove env logging
Jul 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tbd-cms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ jobs:
SANITY_AUTH_TOKEN: ${{ secrets.SANITY_DEPLOY_TOKEN }}
SANITY_STUDIO_PROJECT: ${{ secrets.SANITY_PROJECT_ID }}
SANITY_STUDIO_PROD_DATASET: ${{ secrets.SANITY_DATASET }}
SANITY_STUDIO_PREVIEW_KEY: ${{ secrets.PREVIEW_KEY }}
4 changes: 4 additions & 0 deletions .github/workflows/tbd-site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ jobs:
with:
envkey_SANITY_WEBHOOK_SECRET: ${{ secrets.SANITY_WEBHOOK_SECRET }}
envkey_GITHUB_TOKEN: ${{ secrets.WORKFLOW_PAT }}
envkey_SANITY_PROJECT_ID: ${{ secrets.SANITY_PROJECT_ID }}
envkey_SANITY_DATASET: ${{ secrets.SANITY_DATASET }}
envkey_SANITY_TOKEN: ${{ secrets.SANITY_TOKEN }}
envkey_PREVIEW_KEY: ${{ secrets.PREVIEW_KEY }}
directory: site
- name: Deploy Hosting
uses: FirebaseExtended/action-hosting-deploy@v0
Expand Down
11 changes: 10 additions & 1 deletion cms/lib/desk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { RiTodoLine } from 'react-icons/ri';
import { MdOutlineNewReleases } from 'react-icons/md';

import { AiOutlineFileSearch } from 'react-icons/ai';
import { IoLogoPwa } from 'react-icons/io5';
import { IoLogoPwa, IoSchoolOutline } from 'react-icons/io5';
import { LuPaintbrush2, LuScissors } from 'react-icons/lu';
// import { TfiAnnouncement } from 'react-icons/tfi';
import { SINGLETONS, LANGUAGES } from './constants';
Expand Down Expand Up @@ -113,6 +113,15 @@ export const deskStructure = (
`_type == 'documentation' && (language == 'en' || !defined(language) || language == 'en')`,
),
),
// All base-language tutorial
S.listItem()
.title('Tutorials')
.icon(IoSchoolOutline)
.child(
S.documentTypeList('tutorial').filter(
`_type == 'tutorial' && (language == 'en' || !defined(language) || language == 'en')`,
),
),
// All base-language release notes
S.listItem()
.title('Release Notes')
Expand Down
111 changes: 94 additions & 17 deletions cms/lib/desk/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,110 @@
import { ComponentView } from 'sanity/desk';
import { DeskToolContextValue } from 'sanity/desk';
import { FaRegCopy } from 'react-icons/fa';
import { IoReload } from 'react-icons/io5';
import { RxOpenInNewWindow } from 'react-icons/rx';

/**
*
* @param {Object} context
* @return {ComponentView}
*/
export const Preview = (context: ComponentView) => {
const { document, documentId, schemaType } = context;
export const Preview = (context: DeskToolContextValue) => {
const { document: d, schemaType } = context;
const types = [
'documentation',
'post',
'story',
'tutorial',
// 'landing',
// 'release',
];

if (!types.includes(schemaType.name)) {
return <h1>Preview not supported for this content type</h1>;
}

const base =
process.env.MODE === 'development'
? 'http://localhost:4321'
: 'https://chromeos.dev';
// Site preview URL?
const previewURL = `https://staging.chromeos.dev/en/posts/${document.displayed.slug.current}?id=${document.displayed._id}&rev=${document.displayed._rev}&preview=true`;
console.log(document);
console.log(documentId);
console.log(schemaType);
console.log(previewURL);
const previewURL = `${base}/preview?id=${d.displayed._id}&rev=${
d.displayed._rev
}&key=${encodeURIComponent(process.env.SANITY_STUDIO_PREVIEW_KEY)}`;

const style = {
width: '100%',
height: '50vh',
};
const id = `preview-${Math.round(Math.random() * 1000)}`;

return (
<div>
<h1>Document Preview</h1>
<p>Preview URL: {previewURL}</p>
<h1>Preview</h1>
<div
className="actions"
style={{
display: 'flex',
justifyContent: 'space-between',
paddingInline: '1rem',
paddingBlock: '.5rem',
backgroundColor: '#111',
gap: '1rem',
}}
>
<button
style={{
appearance: 'none',
border: 'none',
backgroundColor: '#111',
display: 'flex',
alignItems: 'center',
gap: '.5rem',
cursor: 'pointer',
}}
onClick={async () => {
await navigator.clipboard.writeText(previewURL);
}}
>
<FaRegCopy></FaRegCopy> Copy URL
</button>
<span
style={{
display: 'flex',
justifyContent: 'space-between',
gap: '1rem',
}}
>
<button
style={{
appearance: 'none',
border: 'none',
backgroundColor: '#111',
cursor: 'pointer',
}}
onClick={() => {
const iframe = document.querySelector(`#${id}`);
if (iframe) iframe.src = previewURL;
}}
>
<IoReload></IoReload>
</button>
<a
href={previewURL}
target="_blank"
rel="noopener noreferrer"
style={{
color: 'white',
}}
>
<RxOpenInNewWindow />
</a>
</span>
</div>
<iframe
title="preview"
src="https://chromeos.dev"
frameBorder="0"
style={style}
src={previewURL}
style={{
width: '100%',
height: '50vh',
}}
id={id}
></iframe>
</div>
);
Expand Down
5 changes: 3 additions & 2 deletions cms/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"version": "1.0.0",
"main": "package.json",
"license": "UNLICENSED",
"license": "Apache-2.0",
"scripts": {
"dev": "sanity dev",
"start": "sanity start",
Expand All @@ -22,7 +22,8 @@
"prettier:fix": "prettier --write .",
"sanity": "sanity",
"sanity:create:singletons": "sanity exec scripts/createSingletons.ts --with-user-token",
"sanity:test:singletons": "TARGET=dev sanity exec scripts/createSingletons.ts --with-user-token"
"sanity:test:singletons": "TARGET=dev sanity exec scripts/createSingletons.ts --with-user-token",
"sanity:pull": "sanity dataset export production && sanity dataset import --replace production.tar.gz development && rm production.tar.gz"
},
"keywords": [
"sanity"
Expand Down
40 changes: 2 additions & 38 deletions cms/schemas/announcement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { defineField, defineType, defineArrayMember } from 'sanity';
import { defineField, defineType } from 'sanity';
import { preview } from '$lib/previews/localization';

export default defineType({
Expand All @@ -29,43 +29,7 @@ export default defineType({
defineField({
name: 'body',
title: 'Announcement',
type: 'array',
of: [
defineArrayMember({
title: 'Block',
type: 'block',
// Styles let you set what your user can mark up blocks with. These
// correspond with HTML tags, but you can set any title or value
// you want and decide how you want to deal with it where you want to
// use your content.
styles: [{ title: 'Normal', value: 'normal' }],
lists: [],
// Marks let you mark up inline text in the block editor.
marks: {
// Decorators usually describe a single property – e.g. a typographic
// preference or highlighting by editors.
decorators: [
{ title: 'Strong', value: 'strong' },
{ title: 'Emphasis', value: 'em' },
],
// Annotations can be any object structure – e.g. a link or a footnote.
annotations: [
{
title: 'Link',
name: 'link',
type: 'object',
fields: [
defineField({
title: 'Source',
name: 'source',
type: 'link',
}),
],
},
],
},
}),
],
type: 'restricted-inline-block',
validation: (Rule) => Rule.required(),
}),
],
Expand Down
82 changes: 82 additions & 0 deletions cms/schemas/fields/restricted-inline-block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* 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 { defineType, defineArrayMember, defineField } from 'sanity';
import { KBDDecorator } from '$components/KBD';

/**
* This is the schema definition for the rich text fields used for
* for this blog studio. When you import it in schemas.js it can be
* reused in other parts of the studio with:
* {
* name: 'someName',
* title: 'Some title',
* type: 'blockContent'
* }
*/
export default defineType({
title: 'Restricted Inline Block Content',
name: 'restricted-inline-block',
type: 'array',
of: [
defineArrayMember({
title: 'Block',
type: 'block',
// Styles let you set what your user can mark up blocks with. These
// correspond with HTML tags, but you can set any title or value
// you want and decide how you want to deal with it where you want to
// use your content.
styles: [{ title: 'Normal', value: 'normal' }],
lists: [],
// Marks let you mark up inline text in the block editor.
marks: {
// Decorators usually describe a single property – e.g. a typographic
// preference or highlighting by editors.
decorators: [
{ title: 'Strong', value: 'strong' },
{ title: 'Emphasis', value: 'em' },
KBDDecorator,
{ title: 'Code', value: 'code' },
],
// Annotations can be any object structure – e.g. a link or a footnote.
annotations: [
{
title: 'Link',
name: 'link',
type: 'object',
fields: [
defineField({
title: 'Source',
name: 'source',
type: 'link',
}),
],
},
{
title: 'Abbreviation',
name: 'abbreviation',
type: 'object',
fields: [
defineField({
name: 'abbreviation',
type: 'abbreviation',
}),
],
},
],
},
}),
],
});
4 changes: 4 additions & 0 deletions cms/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import fullBlockField from '$fields/full-block';
import restrictedBlockField from '$fields/restricted-block';
import inlineBlockField from '$fields/inline-block';
import restrictedInlineBlockField from '$fields/restricted-inline-block';
import cellBlockField from '$fields/cell-block';
import pictureField from '$fields/picture';
import titleField from '$fields/title';
Expand Down Expand Up @@ -79,6 +80,7 @@ import releases from './releases';
import release from './release';
import snippet from './snippet';
import announcement from './announcement';
import tutorial from './tutorial';

export const schemaTypes = [
// Schemas
Expand All @@ -103,11 +105,13 @@ export const schemaTypes = [
release,
snippet,
announcement,
tutorial,

// Fields
fullBlockField,
restrictedBlockField,
inlineBlockField,
restrictedInlineBlockField,
cellBlockField,
pictureField,
titleField,
Expand Down
Loading
Loading