From a56717f88cd6b18de95e21a5ba7acdd403974532 Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Wed, 17 May 2023 14:03:26 -0400 Subject: [PATCH 01/16] Scripts to add unique ID values to each page --- package.json | 1 + scripts/generate-page-ids.mjs | 19 +++++++++++++++++++ scripts/validate-duplicate-ids.mjs | 19 +++++++++++++++++++ yarn.lock | 1 + 4 files changed, 40 insertions(+) create mode 100644 scripts/generate-page-ids.mjs create mode 100644 scripts/validate-duplicate-ids.mjs diff --git a/package.json b/package.json index 465338c..11743f1 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "eslint": "8.13.0", "eslint-config-next": "12.1.5", "eslint-plugin-import": "^2.26.0", + "gray-matter": "^4.0.3", "local-ssl-proxy": "^1.3.0", "mdast-util-mdx": "^2.0.0", "mdast-util-to-markdown": "^1.3.0", diff --git a/scripts/generate-page-ids.mjs b/scripts/generate-page-ids.mjs new file mode 100644 index 0000000..e876292 --- /dev/null +++ b/scripts/generate-page-ids.mjs @@ -0,0 +1,19 @@ +import crypto from 'crypto' +import glob from 'glob' +import fs from 'fs' + +const pages = glob.sync('./content/docs/**/*.md*') + +pages.forEach((pagePath) => { + const id = crypto.randomBytes(4).toString('hex') + const content = fs.readFileSync(pagePath, 'utf8') + if (content.match(/^---\nid: /)) { + console.log(`[Notice] ${pagePath} already has an id`) + } + if (!content.startsWith('---\n')) { + throw new Error(`[Error] ${pagePath} does not have frontmatter`) + } + + const newContent = content.replace(/^---\n/, `---\nid: ${id}\n`) + fs.writeFileSync(pagePath, newContent) +}) diff --git a/scripts/validate-duplicate-ids.mjs b/scripts/validate-duplicate-ids.mjs new file mode 100644 index 0000000..e9d4f73 --- /dev/null +++ b/scripts/validate-duplicate-ids.mjs @@ -0,0 +1,19 @@ +import glob from 'glob' +import fs from 'fs' +import matter from 'gray-matter' + +const pages = glob.sync('./content/docs/**/*.md*') + +const ids = pages.map((pagePath) => { + const rawContent = fs.readFileSync(pagePath, 'utf8') + const { data } = matter(rawContent) + if (!data.id) throw new Error(`[Error] ${pagePath} does not have an id`) + return data.id +}) + +const duplicates = ids.filter((id, index) => ids.indexOf(id) !== index) +if (duplicates.length) { + throw new Error(`[Error] Duplicate ids found: ${duplicates.join(', ')}`) +} + +console.log('No duplicate ids found') diff --git a/yarn.lock b/yarn.lock index 4ee9b45..394e735 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3092,6 +3092,7 @@ __metadata: eslint: 8.13.0 eslint-config-next: 12.1.5 eslint-plugin-import: ^2.26.0 + gray-matter: ^4.0.3 kbar: ^0.1.0-beta.34 local-ssl-proxy: ^1.3.0 markdown-to-jsx: ^7.1.6 From 48b8c8431e7c899567b18790aeac0e09d8b89059 Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Wed, 17 May 2023 14:05:09 -0400 Subject: [PATCH 02/16] Add `id` field to `Doc` --- src/contentlayer/document/Doc.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/contentlayer/document/Doc.ts b/src/contentlayer/document/Doc.ts index af26432..a3cb1dc 100644 --- a/src/contentlayer/document/Doc.ts +++ b/src/contentlayer/document/Doc.ts @@ -15,6 +15,11 @@ export const Doc = defineDocumentType(() => ({ filePathPattern: `docs/**/*.mdx`, contentType: 'mdx', fields: { + id: { + type: 'string', + description: 'Random ID to uniquely identify this doc, even after it moves', + required: true, + }, title: { type: 'string', description: 'The title of the page', From dfce2c8732139faff0069d86496028b66f3e4478 Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Wed, 17 May 2023 14:07:15 -0400 Subject: [PATCH 03/16] Make sure id doesn't start with a number --- scripts/generate-page-ids.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/scripts/generate-page-ids.mjs b/scripts/generate-page-ids.mjs index e876292..651ba16 100644 --- a/scripts/generate-page-ids.mjs +++ b/scripts/generate-page-ids.mjs @@ -4,8 +4,14 @@ import fs from 'fs' const pages = glob.sync('./content/docs/**/*.md*') -pages.forEach((pagePath) => { +function generateId() { const id = crypto.randomBytes(4).toString('hex') + if (id.match(/^\d/)) return generateId() + return id +} + +pages.forEach((pagePath) => { + const id = generateId() const content = fs.readFileSync(pagePath, 'utf8') if (content.match(/^---\nid: /)) { console.log(`[Notice] ${pagePath} already has an id`) From cd9e48697fd2544fd928ef7e052fd2628569a72b Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Wed, 17 May 2023 14:11:10 -0400 Subject: [PATCH 04/16] Add `id` to docs pages --- content/docs/100-getting-started/index.mdx | 1 + content/docs/200-concepts/100-how-contentlayer-works.mdx | 1 + content/docs/200-concepts/200-content-modeling.mdx | 1 + content/docs/200-concepts/300-type-safety.mdx | 1 + content/docs/200-concepts/400-comparison.mdx | 1 + content/docs/200-concepts/index.mdx | 1 + .../docs/300-sources/100-files/100-mapping-document-types.mdx | 1 + content/docs/300-sources/100-files/200-generated-data.mdx | 1 + content/docs/300-sources/100-files/300-generated-types.mdx | 1 + content/docs/300-sources/100-files/400-mdx.mdx | 1 + content/docs/300-sources/100-files/500-images.mdx | 1 + content/docs/300-sources/100-files/index.mdx | 1 + content/docs/300-sources/125-notion/100-getting-started.mdx | 1 + content/docs/300-sources/125-notion/200-configure-databases.mdx | 1 + content/docs/300-sources/125-notion/300-configure-properties.mdx | 1 + content/docs/300-sources/125-notion/400-configure-renderer.mdx | 1 + content/docs/300-sources/125-notion/500-images.mdx | 1 + content/docs/300-sources/125-notion/index.mdx | 1 + content/docs/300-sources/150-remote-files.mdx | 1 + content/docs/300-sources/200-contentful.mdx | 1 + content/docs/300-sources/300-sanity.mdx | 1 + content/docs/300-sources/index.mdx | 1 + content/docs/400-environments/100-nextjs.mdx | 1 + content/docs/400-environments/200-remix.mdx | 1 + content/docs/400-environments/300-svelte.mdx | 1 + content/docs/400-environments/400-astro.mdx | 1 + content/docs/400-environments/500-vite.mdx | 1 + content/docs/400-environments/index.mdx | 1 + content/docs/500-reference/100-cli.mdx | 1 + content/docs/500-reference/200-next-contentlayer.mdx | 1 + content/docs/500-reference/200-source-files/100-make-source.mdx | 1 + .../500-reference/200-source-files/200-define-document-type.mdx | 1 + .../500-reference/200-source-files/300-define-nested-type.mdx | 1 + content/docs/500-reference/200-source-files/400-field-types.mdx | 1 + content/docs/500-reference/200-source-files/index.mdx | 1 + content/docs/500-reference/250-source-notion/100-make-source.mdx | 1 + .../docs/500-reference/250-source-notion/200-define-database.mdx | 1 + content/docs/500-reference/250-source-notion/300-properties.mdx | 1 + content/docs/500-reference/250-source-notion/index.mdx | 1 + content/docs/500-reference/index.mdx | 1 + content/docs/600-integrations/100-stackbit/100-tutorial.mdx | 1 + content/docs/600-integrations/100-stackbit/200-config.mdx | 1 + content/docs/600-integrations/100-stackbit/300-dev-server.mdx | 1 + content/docs/600-integrations/100-stackbit/index.mdx | 1 + content/docs/600-integrations/index.mdx | 1 + content/docs/700-other/100-faq.mdx | 1 + content/docs/700-other/200-roadmap.mdx | 1 + content/docs/700-other/300-changelog.mdx | 1 + content/docs/700-other/400-contributing.mdx | 1 + content/docs/700-other/500-known-problems.mdx | 1 + content/docs/700-other/index.mdx | 1 + content/docs/index.mdx | 1 + 52 files changed, 52 insertions(+) diff --git a/content/docs/100-getting-started/index.mdx b/content/docs/100-getting-started/index.mdx index 6b2121a..ce97059 100644 --- a/content/docs/100-getting-started/index.mdx +++ b/content/docs/100-getting-started/index.mdx @@ -1,4 +1,5 @@ --- +id: cddd76b7 title: Getting Started excerpt: Get comfortable with the basics of Contentlayer by showing how we can quickly build a blog site using Next.js. --- diff --git a/content/docs/200-concepts/100-how-contentlayer-works.mdx b/content/docs/200-concepts/100-how-contentlayer-works.mdx index 85e9718..ec94e0e 100644 --- a/content/docs/200-concepts/100-how-contentlayer-works.mdx +++ b/content/docs/200-concepts/100-how-contentlayer-works.mdx @@ -1,4 +1,5 @@ --- +id: da5b2220 title: How Contentlayer Works excerpt: Contentlayer is the glue between your content and your code. --- diff --git a/content/docs/200-concepts/200-content-modeling.mdx b/content/docs/200-concepts/200-content-modeling.mdx index 384d585..02eb3e5 100644 --- a/content/docs/200-concepts/200-content-modeling.mdx +++ b/content/docs/200-concepts/200-content-modeling.mdx @@ -1,4 +1,5 @@ --- +id: dc68721f title: Content Modeling with Contentlayer nav_title: Content Modeling excerpt: Why content modeling is necessary and how it differs between local and remote sources. diff --git a/content/docs/200-concepts/300-type-safety.mdx b/content/docs/200-concepts/300-type-safety.mdx index 4f172ae..a87c301 100644 --- a/content/docs/200-concepts/300-type-safety.mdx +++ b/content/docs/200-concepts/300-type-safety.mdx @@ -1,4 +1,5 @@ --- +id: e764dcd5 title: Writing Type-Safe Code nav_title: Type Safety excerpt: Though not required, TypeScript is an important piece of Contentlayer. Let us convince you why. diff --git a/content/docs/200-concepts/400-comparison.mdx b/content/docs/200-concepts/400-comparison.mdx index ab378c6..58f45b5 100644 --- a/content/docs/200-concepts/400-comparison.mdx +++ b/content/docs/200-concepts/400-comparison.mdx @@ -1,4 +1,5 @@ --- +id: d7093dfb title: Comparing Contentlayer to Other Tools nav_title: Contentlayer vs X excerpt: Better understand Contentlayer and where it fits by using comparisons to tools that you're familiar with. diff --git a/content/docs/200-concepts/index.mdx b/content/docs/200-concepts/index.mdx index 83d0f3e..c2db649 100644 --- a/content/docs/200-concepts/index.mdx +++ b/content/docs/200-concepts/index.mdx @@ -1,4 +1,5 @@ --- +id: ac167d19 title: Concepts show_child_cards: true excerpt: Background information on how Contentlayer works. diff --git a/content/docs/300-sources/100-files/100-mapping-document-types.mdx b/content/docs/300-sources/100-files/100-mapping-document-types.mdx index ce4767c..2ccf05b 100644 --- a/content/docs/300-sources/100-files/100-mapping-document-types.mdx +++ b/content/docs/300-sources/100-files/100-mapping-document-types.mdx @@ -1,4 +1,5 @@ --- +id: bf100a10 title: Mapping Documents to Document Types nav_title: Mapping Documents to Types excerpt: How Contentlayer determines and sets the type for each document. diff --git a/content/docs/300-sources/100-files/200-generated-data.mdx b/content/docs/300-sources/100-files/200-generated-data.mdx index 676b753..e153c15 100644 --- a/content/docs/300-sources/100-files/200-generated-data.mdx +++ b/content/docs/300-sources/100-files/200-generated-data.mdx @@ -1,4 +1,5 @@ --- +id: bd588cf1 title: Generated Data excerpt: The shape of documents (data) generated by Contentlayer. --- diff --git a/content/docs/300-sources/100-files/300-generated-types.mdx b/content/docs/300-sources/100-files/300-generated-types.mdx index 071bc35..44f6270 100644 --- a/content/docs/300-sources/100-files/300-generated-types.mdx +++ b/content/docs/300-sources/100-files/300-generated-types.mdx @@ -1,4 +1,5 @@ --- +id: fda1d801 title: Generated Type Definitions excerpt: Contentlayer automatically generates type definitions for content that lives locally. --- diff --git a/content/docs/300-sources/100-files/400-mdx.mdx b/content/docs/300-sources/100-files/400-mdx.mdx index 27ce453..b109b3b 100644 --- a/content/docs/300-sources/100-files/400-mdx.mdx +++ b/content/docs/300-sources/100-files/400-mdx.mdx @@ -1,4 +1,5 @@ --- +id: d747e46d title: Processing MDX Files nav_title: MDX excerpt: How Contentlayer processes MDX when using local files as the content source. diff --git a/content/docs/300-sources/100-files/500-images.mdx b/content/docs/300-sources/100-files/500-images.mdx index dddc5cf..1fa0d68 100644 --- a/content/docs/300-sources/100-files/500-images.mdx +++ b/content/docs/300-sources/100-files/500-images.mdx @@ -1,4 +1,5 @@ --- +id: eeed57ba title: Working with Images nav_title: Images excerpt: Options on image processing when using local files as your content source. diff --git a/content/docs/300-sources/100-files/index.mdx b/content/docs/300-sources/100-files/index.mdx index db7d9d6..fc9f744 100644 --- a/content/docs/300-sources/100-files/index.mdx +++ b/content/docs/300-sources/100-files/index.mdx @@ -1,4 +1,5 @@ --- +id: ae74398f title: Files Source nav_title: Files collapsible: true diff --git a/content/docs/300-sources/125-notion/100-getting-started.mdx b/content/docs/300-sources/125-notion/100-getting-started.mdx index 3cd8a7b..e80d746 100644 --- a/content/docs/300-sources/125-notion/100-getting-started.mdx +++ b/content/docs/300-sources/125-notion/100-getting-started.mdx @@ -1,4 +1,5 @@ --- +id: a47597e1 title: Getting started nav_title: Getting started excerpt: How Contentlayer determines and sets the type for each document. diff --git a/content/docs/300-sources/125-notion/200-configure-databases.mdx b/content/docs/300-sources/125-notion/200-configure-databases.mdx index c5e3238..5fcbe99 100644 --- a/content/docs/300-sources/125-notion/200-configure-databases.mdx +++ b/content/docs/300-sources/125-notion/200-configure-databases.mdx @@ -1,4 +1,5 @@ --- +id: a4add649 title: Configure databases nav_title: Configure databases excerpt: How to configure Notion databases using contentlayer-source-notion. diff --git a/content/docs/300-sources/125-notion/300-configure-properties.mdx b/content/docs/300-sources/125-notion/300-configure-properties.mdx index 4bb6afb..7cebe35 100644 --- a/content/docs/300-sources/125-notion/300-configure-properties.mdx +++ b/content/docs/300-sources/125-notion/300-configure-properties.mdx @@ -1,4 +1,5 @@ --- +id: e0d46d0d title: Configure properties nav_title: Configure properties excerpt: How to configure properties using contentlayer-source-notion. diff --git a/content/docs/300-sources/125-notion/400-configure-renderer.mdx b/content/docs/300-sources/125-notion/400-configure-renderer.mdx index f252bff..8451d70 100644 --- a/content/docs/300-sources/125-notion/400-configure-renderer.mdx +++ b/content/docs/300-sources/125-notion/400-configure-renderer.mdx @@ -1,4 +1,5 @@ --- +id: c00ae003 title: Configure renderer nav_title: Configure renderer excerpt: How to configure how the HTML is generated for Rich text content with contentlayer-source-notion. diff --git a/content/docs/300-sources/125-notion/500-images.mdx b/content/docs/300-sources/125-notion/500-images.mdx index b2bd7d5..227363a 100644 --- a/content/docs/300-sources/125-notion/500-images.mdx +++ b/content/docs/300-sources/125-notion/500-images.mdx @@ -1,4 +1,5 @@ --- +id: e3a04016 title: Images nav_title: Images excerpt: Options on image processing when using Notion as your content source. diff --git a/content/docs/300-sources/125-notion/index.mdx b/content/docs/300-sources/125-notion/index.mdx index 93f5ed5..aa748a8 100644 --- a/content/docs/300-sources/125-notion/index.mdx +++ b/content/docs/300-sources/125-notion/index.mdx @@ -1,4 +1,5 @@ --- +id: b2ce5957 title: Notion Source nav_title: Notion label: Experimental diff --git a/content/docs/300-sources/150-remote-files.mdx b/content/docs/300-sources/150-remote-files.mdx index d35cd70..6181e4d 100644 --- a/content/docs/300-sources/150-remote-files.mdx +++ b/content/docs/300-sources/150-remote-files.mdx @@ -1,4 +1,5 @@ --- +id: fbb47906 title: Remote Files label: Experimental excerpt: How to use Contentlayer with remote files as content source (e.g. Git repo) diff --git a/content/docs/300-sources/200-contentful.mdx b/content/docs/300-sources/200-contentful.mdx index 2d702fd..21aa670 100644 --- a/content/docs/300-sources/200-contentful.mdx +++ b/content/docs/300-sources/200-contentful.mdx @@ -1,4 +1,5 @@ --- +id: d72dff47 title: Contentful label: Planned excerpt: We are planning to officially support Contentful. Add your vote to help us prioritize the work. diff --git a/content/docs/300-sources/300-sanity.mdx b/content/docs/300-sources/300-sanity.mdx index b308455..f9c73e7 100644 --- a/content/docs/300-sources/300-sanity.mdx +++ b/content/docs/300-sources/300-sanity.mdx @@ -1,4 +1,5 @@ --- +id: c4fdd0f7 title: Sanity label: Considering excerpt: We're considering officially supporting Sanity. Add your vote. diff --git a/content/docs/300-sources/index.mdx b/content/docs/300-sources/index.mdx index 56d022f..4a8081b 100644 --- a/content/docs/300-sources/index.mdx +++ b/content/docs/300-sources/index.mdx @@ -1,4 +1,5 @@ --- +id: acc47cf6 title: Content Sources nav_title: Sources excerpt: Solving specific scenarios using Contentlayer. diff --git a/content/docs/400-environments/100-nextjs.mdx b/content/docs/400-environments/100-nextjs.mdx index ee02e6a..2c41d2c 100644 --- a/content/docs/400-environments/100-nextjs.mdx +++ b/content/docs/400-environments/100-nextjs.mdx @@ -1,4 +1,5 @@ --- +id: dcf8e39e title: Next.js excerpt: Use the next-contentlayer plugin to tightly integrate Contentlayer into a Next.js project. --- diff --git a/content/docs/400-environments/200-remix.mdx b/content/docs/400-environments/200-remix.mdx index d88c627..560e824 100644 --- a/content/docs/400-environments/200-remix.mdx +++ b/content/docs/400-environments/200-remix.mdx @@ -1,4 +1,5 @@ --- +id: b3975f99 title: Remix label: Considering excerpt: We're considering officially supporting Remix. Add your vote. diff --git a/content/docs/400-environments/300-svelte.mdx b/content/docs/400-environments/300-svelte.mdx index 8248ef2..bdff60a 100644 --- a/content/docs/400-environments/300-svelte.mdx +++ b/content/docs/400-environments/300-svelte.mdx @@ -1,4 +1,5 @@ --- +id: efe6735d title: SvelteKit label: Considering excerpt: We're considering officially supporting Svelte and SvelteKit. Add your vote. diff --git a/content/docs/400-environments/400-astro.mdx b/content/docs/400-environments/400-astro.mdx index 481246a..930284d 100644 --- a/content/docs/400-environments/400-astro.mdx +++ b/content/docs/400-environments/400-astro.mdx @@ -1,4 +1,5 @@ --- +id: d57135c9 title: Astro label: Considering excerpt: We're considering officially supporting Astro. Add your vote. diff --git a/content/docs/400-environments/500-vite.mdx b/content/docs/400-environments/500-vite.mdx index daff8c2..6207b09 100644 --- a/content/docs/400-environments/500-vite.mdx +++ b/content/docs/400-environments/500-vite.mdx @@ -1,4 +1,5 @@ --- +id: ba80b355 title: Vite label: Considering excerpt: We're considering officially supporting Vite. Add your vote. diff --git a/content/docs/400-environments/index.mdx b/content/docs/400-environments/index.mdx index bda00e2..222f3de 100644 --- a/content/docs/400-environments/index.mdx +++ b/content/docs/400-environments/index.mdx @@ -1,4 +1,5 @@ --- +id: c6df80ab title: Environments excerpt: Solving specific scenarios using Contentlayer. show_child_cards: true diff --git a/content/docs/500-reference/100-cli.mdx b/content/docs/500-reference/100-cli.mdx index d45966b..5f234ec 100644 --- a/content/docs/500-reference/100-cli.mdx +++ b/content/docs/500-reference/100-cli.mdx @@ -1,4 +1,5 @@ --- +id: e9e2f788 title: Contentlayer CLI nav_title: CLI excerpt: Working with Contentlayer on the command line. diff --git a/content/docs/500-reference/200-next-contentlayer.mdx b/content/docs/500-reference/200-next-contentlayer.mdx index 9d846ce..8134d77 100644 --- a/content/docs/500-reference/200-next-contentlayer.mdx +++ b/content/docs/500-reference/200-next-contentlayer.mdx @@ -1,4 +1,5 @@ --- +id: e6e7eb3a title: next-contentlayer excerpt: Helper for improving the experience when developing with Next.js. --- diff --git a/content/docs/500-reference/200-source-files/100-make-source.mdx b/content/docs/500-reference/200-source-files/100-make-source.mdx index 1ed5b83..d7e62f8 100644 --- a/content/docs/500-reference/200-source-files/100-make-source.mdx +++ b/content/docs/500-reference/200-source-files/100-make-source.mdx @@ -1,4 +1,5 @@ --- +id: a5ba4922 title: makeSource excerpt: makeSource provides Contentlayer with the schema and configuration when using local files as the content source. --- diff --git a/content/docs/500-reference/200-source-files/200-define-document-type.mdx b/content/docs/500-reference/200-source-files/200-define-document-type.mdx index 61b9f63..e3a06d2 100644 --- a/content/docs/500-reference/200-source-files/200-define-document-type.mdx +++ b/content/docs/500-reference/200-source-files/200-define-document-type.mdx @@ -1,4 +1,5 @@ --- +id: eb9db60e title: defineDocumentType excerpt: Technical reference for defining a document's type schema. --- diff --git a/content/docs/500-reference/200-source-files/300-define-nested-type.mdx b/content/docs/500-reference/200-source-files/300-define-nested-type.mdx index bd29597..57b892b 100644 --- a/content/docs/500-reference/200-source-files/300-define-nested-type.mdx +++ b/content/docs/500-reference/200-source-files/300-define-nested-type.mdx @@ -1,4 +1,5 @@ --- +id: eeeb4ab5 title: defineNestedType excerpt: Technical reference for defining a nested document type schema. --- diff --git a/content/docs/500-reference/200-source-files/400-field-types.mdx b/content/docs/500-reference/200-source-files/400-field-types.mdx index 17b8009..bdce231 100644 --- a/content/docs/500-reference/200-source-files/400-field-types.mdx +++ b/content/docs/500-reference/200-source-files/400-field-types.mdx @@ -1,4 +1,5 @@ --- +id: defe41e9 title: Field Types Reference nav_title: Field Types excerpt: Technical reference for field types when using the local files content source. diff --git a/content/docs/500-reference/200-source-files/index.mdx b/content/docs/500-reference/200-source-files/index.mdx index 5560a82..de37540 100644 --- a/content/docs/500-reference/200-source-files/index.mdx +++ b/content/docs/500-reference/200-source-files/index.mdx @@ -1,4 +1,5 @@ --- +id: f4638f76 title: '@contentlayer/source-files' excerpt: API reference for working with local files (Git CMS). collapsible: true diff --git a/content/docs/500-reference/250-source-notion/100-make-source.mdx b/content/docs/500-reference/250-source-notion/100-make-source.mdx index 8f9a8ea..56b330b 100644 --- a/content/docs/500-reference/250-source-notion/100-make-source.mdx +++ b/content/docs/500-reference/250-source-notion/100-make-source.mdx @@ -1,4 +1,5 @@ --- +id: fa487097 title: makeSource excerpt: makeSource provides Contentlayer with the schema and configuration when using local files as the content source. --- diff --git a/content/docs/500-reference/250-source-notion/200-define-database.mdx b/content/docs/500-reference/250-source-notion/200-define-database.mdx index cc69378..4f80b13 100644 --- a/content/docs/500-reference/250-source-notion/200-define-database.mdx +++ b/content/docs/500-reference/250-source-notion/200-define-database.mdx @@ -1,4 +1,5 @@ --- +id: cabc1d04 title: defineDatabase excerpt: defineDatabase provides Contentlayer with the schema and configuration when using local files as the content source. --- diff --git a/content/docs/500-reference/250-source-notion/300-properties.mdx b/content/docs/500-reference/250-source-notion/300-properties.mdx index aecf405..06d2b70 100644 --- a/content/docs/500-reference/250-source-notion/300-properties.mdx +++ b/content/docs/500-reference/250-source-notion/300-properties.mdx @@ -1,4 +1,5 @@ --- +id: e6e079ee title: Properties excerpt: defineDatabase provides Contentlayer with the schema and configuration when using local files as the content source. --- diff --git a/content/docs/500-reference/250-source-notion/index.mdx b/content/docs/500-reference/250-source-notion/index.mdx index 2413bc0..bd9fea6 100644 --- a/content/docs/500-reference/250-source-notion/index.mdx +++ b/content/docs/500-reference/250-source-notion/index.mdx @@ -1,4 +1,5 @@ --- +id: c60229ba title: '@contentlayer/source-notion' excerpt: API reference for working with Notion. collapsible: true diff --git a/content/docs/500-reference/index.mdx b/content/docs/500-reference/index.mdx index 16132e2..e1eb0c6 100644 --- a/content/docs/500-reference/index.mdx +++ b/content/docs/500-reference/index.mdx @@ -1,4 +1,5 @@ --- +id: abcab6a5 title: API Reference show_child_cards: true excerpt: Technical API reference for Contentlayer usage. diff --git a/content/docs/600-integrations/100-stackbit/100-tutorial.mdx b/content/docs/600-integrations/100-stackbit/100-tutorial.mdx index d948c7f..791dfd4 100644 --- a/content/docs/600-integrations/100-stackbit/100-tutorial.mdx +++ b/content/docs/600-integrations/100-stackbit/100-tutorial.mdx @@ -1,4 +1,5 @@ --- +id: a5272b55 title: Stackbit + Contentlayer Tutorial nav_title: Basic Tutorial excerpt: Learn how to use Stackbit and Contentlayer to add visual editing to a Next.js application. diff --git a/content/docs/600-integrations/100-stackbit/200-config.mdx b/content/docs/600-integrations/100-stackbit/200-config.mdx index b4ad655..55163aa 100644 --- a/content/docs/600-integrations/100-stackbit/200-config.mdx +++ b/content/docs/600-integrations/100-stackbit/200-config.mdx @@ -1,4 +1,5 @@ --- +id: ccd7fd6a title: Stackbit Configuration nav_title: Configuration API excerpt: API reference for transforming a Stackbit configuration object into Contentlayer config for source-files. diff --git a/content/docs/600-integrations/100-stackbit/300-dev-server.mdx b/content/docs/600-integrations/100-stackbit/300-dev-server.mdx index c726979..aa86673 100644 --- a/content/docs/600-integrations/100-stackbit/300-dev-server.mdx +++ b/content/docs/600-integrations/100-stackbit/300-dev-server.mdx @@ -1,4 +1,5 @@ --- +id: f1dfe99b title: Stackbit Development Server nav_title: Development Server excerpt: Hook the Stackbit development server into Next.js and Contentlayer. diff --git a/content/docs/600-integrations/100-stackbit/index.mdx b/content/docs/600-integrations/100-stackbit/index.mdx index fca6f91..41622d6 100644 --- a/content/docs/600-integrations/100-stackbit/index.mdx +++ b/content/docs/600-integrations/100-stackbit/index.mdx @@ -1,4 +1,5 @@ --- +id: b1141d65 title: Stackbit excerpt: Stackbit is a composable visual editor that supports multiple content sources and site frameworks. label: Experimental diff --git a/content/docs/600-integrations/index.mdx b/content/docs/600-integrations/index.mdx index a2688bb..b97f1b7 100644 --- a/content/docs/600-integrations/index.mdx +++ b/content/docs/600-integrations/index.mdx @@ -1,4 +1,5 @@ --- +id: ed449e02 title: Integrations excerpt: Connections to other services that are not sources or frameworks show_child_cards: true diff --git a/content/docs/700-other/100-faq.mdx b/content/docs/700-other/100-faq.mdx index 170fab3..e7e5473 100644 --- a/content/docs/700-other/100-faq.mdx +++ b/content/docs/700-other/100-faq.mdx @@ -1,4 +1,5 @@ --- +id: e58c2f47 title: Frequently Asked Questions nav_title: FAQ excerpt: Answers to the most common questions about Contentlayer. diff --git a/content/docs/700-other/200-roadmap.mdx b/content/docs/700-other/200-roadmap.mdx index 847a1ad..e4216cc 100644 --- a/content/docs/700-other/200-roadmap.mdx +++ b/content/docs/700-other/200-roadmap.mdx @@ -1,4 +1,5 @@ --- +id: ce0cb3aa title: Roadmap excerpt: Get a picture of where we're going with upcoming releases. --- diff --git a/content/docs/700-other/300-changelog.mdx b/content/docs/700-other/300-changelog.mdx index cf915d2..80b0a92 100644 --- a/content/docs/700-other/300-changelog.mdx +++ b/content/docs/700-other/300-changelog.mdx @@ -1,4 +1,5 @@ --- +id: eec1d8c0 title: Changelog excerpt: Information on detailed notes for previous releases --- diff --git a/content/docs/700-other/400-contributing.mdx b/content/docs/700-other/400-contributing.mdx index a0812d5..aeb0556 100644 --- a/content/docs/700-other/400-contributing.mdx +++ b/content/docs/700-other/400-contributing.mdx @@ -1,4 +1,5 @@ --- +id: d739035b title: Contributing excerpt: Multiple ways to get more involved with Contentlayer. --- diff --git a/content/docs/700-other/500-known-problems.mdx b/content/docs/700-other/500-known-problems.mdx index 4eccf8b..b99cb0e 100644 --- a/content/docs/700-other/500-known-problems.mdx +++ b/content/docs/700-other/500-known-problems.mdx @@ -1,4 +1,5 @@ --- +id: cdffa1e4 title: Known Problems excerpt: Open bugs and other known issues. --- diff --git a/content/docs/700-other/index.mdx b/content/docs/700-other/index.mdx index 0e22cb8..3e0232b 100644 --- a/content/docs/700-other/index.mdx +++ b/content/docs/700-other/index.mdx @@ -1,4 +1,5 @@ --- +id: b3a6b480 title: Other show_child_cards: true excerpt: A collection of other resources to help you learn more, stay up to date, and contribute. diff --git a/content/docs/index.mdx b/content/docs/index.mdx index f4ca2da..6994ba4 100644 --- a/content/docs/index.mdx +++ b/content/docs/index.mdx @@ -1,4 +1,5 @@ --- +id: aa80fd13 title: Contentlayer Documentation excerpt: Contentlayer is a content preprocessor that validates and transforms your content into type-safe JSON you can easily import into your application. --- From 8ddf09b77b90ec85c2a2c16d2bf50e13ec915729 Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Wed, 17 May 2023 14:11:33 -0400 Subject: [PATCH 05/16] Collect skipped pages --- scripts/generate-page-ids.mjs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/generate-page-ids.mjs b/scripts/generate-page-ids.mjs index 651ba16..eefb744 100644 --- a/scripts/generate-page-ids.mjs +++ b/scripts/generate-page-ids.mjs @@ -10,11 +10,14 @@ function generateId() { return id } +const skipped = [] + pages.forEach((pagePath) => { const id = generateId() const content = fs.readFileSync(pagePath, 'utf8') if (content.match(/^---\nid: /)) { - console.log(`[Notice] ${pagePath} already has an id`) + skipped.push(pagePath) + return } if (!content.startsWith('---\n')) { throw new Error(`[Error] ${pagePath} does not have frontmatter`) @@ -22,4 +25,9 @@ pages.forEach((pagePath) => { const newContent = content.replace(/^---\n/, `---\nid: ${id}\n`) fs.writeFileSync(pagePath, newContent) + console.log(`[New ID] ${pagePath} -> ${id}`) }) + +if (skipped.length) { + console.log(`[Skipped] ${skipped.length} with existing ids`) +} From 49776cc48e3d49e9a3391cbaa728bf63a6b439ce Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Wed, 17 May 2023 14:14:37 -0400 Subject: [PATCH 06/16] Append `id` to `url_path` if document has the path Won't use global content id for non doc pages --- src/contentlayer/utils.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/contentlayer/utils.ts b/src/contentlayer/utils.ts index 6b73490..5dd6dc6 100644 --- a/src/contentlayer/utils.ts +++ b/src/contentlayer/utils.ts @@ -5,7 +5,9 @@ import path from 'node:path' export const contentDirPath = 'content' export const urlFromFilePath = (doc: DocumentGen): string => { - return doc._raw.flattenedPath.replace(/pages\/?/, '') + let urlPath = doc._raw.flattenedPath.replace(/pages\/?/, '') + if ('id' in doc) urlPath += `-${doc.id}` + return urlPath } export const getLastEditedDate = async (doc: DocumentGen): Promise => { From 4c428ea702581c072da578e9c35646a63e65d628 Mon Sep 17 00:00:00 2001 From: Sean C Davis Date: Wed, 17 May 2023 15:06:01 -0400 Subject: [PATCH 07/16] [WIP] Random ID values --- src/components/docs/DocsNavigation.tsx | 4 ++-- src/contentlayer/document/Doc.ts | 2 +- src/contentlayer/utils.ts | 8 +++++++- src/pages/docs/[[...slug]].tsx | 13 +++++++------ src/utils/build-docs-tree.ts | 6 ++++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/components/docs/DocsNavigation.tsx b/src/components/docs/DocsNavigation.tsx index 717de4e..c6bdd96 100644 --- a/src/components/docs/DocsNavigation.tsx +++ b/src/components/docs/DocsNavigation.tsx @@ -32,13 +32,13 @@ const NavLink: FC<{ )} > - + {title} {label && {collapsible && ( -