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

@astrojs/markdoc #6209

Merged
merged 172 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
e5d009a
chore: integration setup
bholmesdev Feb 6, 2023
5315c50
feat: get markdoc contents
bholmesdev Feb 6, 2023
00da073
wip: expose Markdoc from integration
bholmesdev Feb 6, 2023
30815b4
feat: basic Astro renderer in with-markdoc
bholmesdev Feb 6, 2023
9e5c5af
fix: component render bug
bholmesdev Feb 6, 2023
4b45522
deps: stringify-attributes
bholmesdev Feb 6, 2023
2b81656
fix: render attributes to html
bholmesdev Feb 6, 2023
926c82d
wip: play with separate markdoc config
bholmesdev Feb 6, 2023
65846f4
wip: get dream API for file loader working
bholmesdev Feb 7, 2023
39ce218
chore: unit tests
bholmesdev Feb 7, 2023
b97ea12
deps: graymatter
bholmesdev Feb 7, 2023
092a1b1
feat: addContentEntryType integration hook
bholmesdev Feb 7, 2023
10c8fa1
deps: move to @astrojs/markdoc
bholmesdev Feb 8, 2023
b64e64b
feat: move Renderer to markdoc, get Content component!
bholmesdev Feb 8, 2023
a89fb2f
wip: scaffold content types
bholmesdev Feb 8, 2023
2816b4f
deps: mdx
bholmesdev Feb 8, 2023
3ba5253
wip: move mdx to collection type API
bholmesdev Feb 8, 2023
e4d38c3
refactor: move plain md to content entry type
bholmesdev Feb 9, 2023
e17e873
refactor: pass file contents
bholmesdev Feb 9, 2023
bfe35ab
oops, forgot to commit untracked
bholmesdev Feb 9, 2023
25aefb1
fix: markdoc.config loading
bholmesdev Feb 9, 2023
42dd981
refactor: remove fallback loader
bholmesdev Feb 9, 2023
32cf9ad
chore: remove unused dream file
bholmesdev Feb 9, 2023
1194763
deps: devalue, test fixture
bholmesdev Feb 9, 2023
2159ad1
test: entry and collections parse
bholmesdev Feb 9, 2023
8fc6c58
play: make sure md also works
bholmesdev Feb 10, 2023
18ad952
deps: add shiki for Code comp error
bholmesdev Feb 10, 2023
03d96d2
fix: remove "components" from tsconfig
bholmesdev Feb 10, 2023
6ac351e
chore: ignore `.astro` type error
bholmesdev Feb 10, 2023
10a9df6
fix: avoid import if no config present (prod build error)
bholmesdev Feb 10, 2023
39676ac
fix: stop bundling markdoc for isTag
bholmesdev Feb 10, 2023
260bde4
test: prod builds
bholmesdev Feb 10, 2023
bce7eb6
test: content component dev and build
bholmesdev Feb 10, 2023
24efa3b
chore: Markdoc working! log
bholmesdev Feb 10, 2023
9239339
fix: ContentEntryType import
bholmesdev Feb 10, 2023
be67224
chore: remove content-types. Too early!
bholmesdev Feb 10, 2023
e9e37cb
chore: remove unused options object
bholmesdev Feb 10, 2023
d57f5d1
play: add docs example with Aside and Since ported
bholmesdev Feb 10, 2023
9a1b274
chore: with-markdoc strictNullChecks
bholmesdev Feb 13, 2023
2852066
chore: unused file
bholmesdev Feb 13, 2023
576b481
feat: allow Render type injection
bholmesdev Feb 13, 2023
8e3f4ca
feat: content prop types for markdoc!
bholmesdev Feb 13, 2023
a19c774
chore: clean up Markdoc starter to essentials
bholmesdev Feb 13, 2023
6858350
chore: unused style tag
bholmesdev Feb 13, 2023
2b07210
chore: remove unused deps
bholmesdev Feb 13, 2023
ea58fdb
fix: glob for single content extension
bholmesdev Feb 13, 2023
9d41ea3
chore: remove unused fixture dep
bholmesdev Feb 13, 2023
1ebea26
chore: remove markdoc.config loader
bholmesdev Feb 13, 2023
a756e75
docs: update example README
bholmesdev Feb 13, 2023
f760756
docs: @astrojs/markdoc README intro
bholmesdev Feb 13, 2023
4c65283
fix: line endings in test
bholmesdev Feb 13, 2023
a4a7f99
docs: add usage and examples to Markdoc README
bholmesdev Feb 13, 2023
1297341
docs: change with-markdoc title
bholmesdev Feb 14, 2023
7e9b220
docs: README edits
bholmesdev Feb 14, 2023
d6137d0
refactor: clean up astroNode
bholmesdev Feb 14, 2023
24ea490
nit: reorder type import
bholmesdev Feb 14, 2023
80a5015
docs: add note on Aside src
bholmesdev Feb 14, 2023
61a3c0f
chore: changeset
bholmesdev Feb 14, 2023
7d69cba
nit: 0.0.0 to avoid version bump
bholmesdev Feb 14, 2023
ceb3369
fix: lock
bholmesdev Feb 14, 2023
d24883f
refactor: remove unneeded async
bholmesdev Feb 14, 2023
785bd20
fix: import types from @astrojs/markdoc
bholmesdev Feb 14, 2023
702ca06
fix: type inferencing in preview
bholmesdev Feb 14, 2023
9f0d50d
fix: remove unneeded html-escaper
bholmesdev Feb 14, 2023
7331ce6
deps: remove html-escaper
bholmesdev Feb 14, 2023
a47e1b7
feat: support `.md` overrides for content collections
bholmesdev Feb 14, 2023
5c16a5c
chore: mdoc -> md
bholmesdev Feb 14, 2023
3db67a2
feat: generate `.md` types override
bholmesdev Feb 14, 2023
c16e796
Revert "feat: support `.md` overrides for content collections"
bholmesdev Feb 15, 2023
ce726d0
Squashed commit of `markdoc-poc`
bholmesdev Feb 16, 2023
f7dbbbe
Squashed commit of `markdoc-poc`
bholmesdev Feb 16, 2023
6c24825
feat: add `--perf` flag to skip md plugins
bholmesdev Feb 16, 2023
d0fe784
wip: performance pkg with md fixture
bholmesdev Feb 16, 2023
4040920
refactor: move rendering to util
bholmesdev Feb 16, 2023
78f3299
refactor: generate posts instead of commiting
bholmesdev Feb 16, 2023
c498b63
deps: npm-run-all
bholmesdev Feb 16, 2023
170dfc0
chore: mdoc and mdx fixtures
bholmesdev Feb 16, 2023
2e75bb0
chore: remove generated files from git
bholmesdev Feb 27, 2023
117d74b
chore: lockfile
bholmesdev Feb 27, 2023
fe9f086
chore: remove .astro types from remote
bholmesdev Feb 27, 2023
8e68877
refactor: --perf -> --internal-ci-perf
bholmesdev Feb 27, 2023
42c15c6
chore: log ext and directory on write
bholmesdev Feb 27, 2023
e0a2146
refactor: --perf -> env var
bholmesdev Feb 27, 2023
f013557
feat: add perf benchmark check to mdx
bholmesdev Feb 27, 2023
6c80241
refactor: isPerfBenchmark
bholmesdev Feb 27, 2023
d8bfeb1
chore: refine generated ignore
bholmesdev Feb 27, 2023
38e2960
feat: test simple and with-components cases
bholmesdev Feb 27, 2023
274981f
chore: remove old --internal-ci reference
bholmesdev Feb 27, 2023
9821b77
refactor: ASTRO_CI_PERFORMANCE_RUN -> ASTRO_PERFORMANCE_BENCHMARK
bholmesdev Feb 28, 2023
776782a
chore: remove accidental file
bholmesdev Feb 28, 2023
b6f752a
feat: add react-component render benchmark
bholmesdev Feb 28, 2023
67e4746
chore: add `--format` flag to benchmark
bholmesdev Feb 28, 2023
7d9eb01
refactor: move markdoc transform to build time
bholmesdev Mar 1, 2023
4df2fce
docs: only used in content collections
bholmesdev Mar 1, 2023
0ff5274
chore: use Markdoc terms for transform
bholmesdev Mar 1, 2023
5966a9f
refactor: remove Markdoc export
bholmesdev Mar 1, 2023
95dab53
refactor: remove advanced component API
bholmesdev Mar 1, 2023
4186664
test: update fixture to match new config
bholmesdev Mar 1, 2023
1d79ba4
chore: with-markdoc filetree
bholmesdev Mar 1, 2023
246a1f8
docs: add "exclusively" to README
bholmesdev Mar 1, 2023
eeaa3de
docs: query for -> query your collection
bholmesdev Mar 1, 2023
aff5a67
docs: update config to new Markdoc options
bholmesdev Mar 1, 2023
2c5d2eb
docs: astro-ui-frameworks -> astro-components
bholmesdev Mar 1, 2023
fc30be6
edit: add client component instructions
bholmesdev Mar 1, 2023
63483d5
nit: add "today" to imply future support
bholmesdev Mar 1, 2023
253ea68
docs: add separate HTML and component examples
bholmesdev Mar 1, 2023
b55a2c9
fix: inconsistent tabs v spaces
bholmesdev Mar 1, 2023
6fb8a60
fix: indentation
bholmesdev Mar 1, 2023
9d2b3ca
deps: zod
bholmesdev Mar 2, 2023
781ff28
chore: check components are capitalized names
bholmesdev Mar 2, 2023
e820060
chore: raise error if no matching component found
bholmesdev Mar 2, 2023
afdba11
chore: hand `mjs` highlighting in error overlay
bholmesdev Mar 2, 2023
041f606
chore: validate tags and nodes
bholmesdev Mar 2, 2023
6217b7a
refactor: use MarkdocError on render errors
bholmesdev Mar 2, 2023
c876d3f
fix: handle possible cache miss
bholmesdev Mar 2, 2023
76cc6a1
chore: use error hint
bholmesdev Mar 2, 2023
5e75515
test: update Markdoc node config test
bholmesdev Mar 2, 2023
ed7c636
chore: clarify Markdoc config
bholmesdev Mar 3, 2023
80919b3
docs: reshuffle note
bholmesdev Mar 3, 2023
8470a3e
chore: update to `nodes` rec
bholmesdev Mar 3, 2023
940053b
docs: clarify Markdoc attributes
bholmesdev Mar 3, 2023
9125932
docs: add editor integration
bholmesdev Mar 3, 2023
64948f6
chore: update example coding challenge
bholmesdev Mar 3, 2023
dcd4ed1
chore: update DocsContent comments
bholmesdev Mar 3, 2023
1b473e5
fix: cant find zod for some reason
bholmesdev Mar 3, 2023
60c3de4
fix: potentially unreliable cache
bholmesdev Mar 3, 2023
f67a9c1
chore: remove revealSecret from ex
bholmesdev Mar 3, 2023
cbcfcf7
wip: forward slash??
bholmesdev Mar 3, 2023
08a9446
fix: forward slash.
bholmesdev Mar 3, 2023
a8e71cf
chore: lint
bholmesdev Mar 3, 2023
90f494f
chore: ignore statements
bholmesdev Mar 3, 2023
64adb44
chore: clarify semi-private hooks
bholmesdev Mar 3, 2023
8806c57
docs: with-mdx -> with-markdoc
bholmesdev Mar 3, 2023
74f019c
nit: don't capitalize cc
bholmesdev Mar 3, 2023
d19848c
docs: :::
bholmesdev Mar 3, 2023
af5a2a0
nit: remove IFFE
bholmesdev Mar 6, 2023
bd7f25d
chore: remove accidental changelog
bholmesdev Mar 6, 2023
45fac99
nit: attempt pathToFileURL
bholmesdev Mar 6, 2023
dda8cf1
nit: tested if
bholmesdev Mar 6, 2023
331ebd4
fix: smartypants should be avoided in benchmark!
bholmesdev Mar 6, 2023
7ea9414
nit: remove `any`
bholmesdev Mar 6, 2023
aff11bb
nit: extract component zod obj
bholmesdev Mar 6, 2023
7eddf99
fix: move validateComponents to render comp
bholmesdev Mar 6, 2023
aec7a09
nit: remove unused return
bholmesdev Mar 6, 2023
1de4190
nit: move shiki highlighter consts to outer scope
bholmesdev Mar 6, 2023
e467e48
nit: remove `any` from mdx
bholmesdev Mar 6, 2023
4226b03
refactor: add type defs for private integration hooks
bholmesdev Mar 6, 2023
5fce7a2
fix: type error in mdx defaults
bholmesdev Mar 6, 2023
a3d9539
fix: broke extendMarkdownConfig, oops!
bholmesdev Mar 6, 2023
6e8ba96
Revert "nit: attempt pathToFileURL"
bholmesdev Mar 6, 2023
73af50b
fix: only validate when components is defined
bholmesdev Mar 6, 2023
9488ec7
fix: remove types from git
bholmesdev Mar 6, 2023
d1d4cc5
fix: migrate mdoc perf benchmark to new config
bholmesdev Mar 6, 2023
80485d6
chore: delete more sneaky types
bholmesdev Mar 6, 2023
4acb749
docs: add usage to changeset
bholmesdev Mar 6, 2023
28f0959
docs: update config example in README
bholmesdev Mar 6, 2023
17c0a9d
docs: add manual rendering instructions
bholmesdev Mar 6, 2023
47528db
Update examples/with-markdoc/README.md
bholmesdev Mar 6, 2023
0c09c58
docs: reorder configuration options
bholmesdev Mar 6, 2023
739789f
Merge branch 'markdoc-poc' of github.com:withastro/astro into markdoc…
bholmesdev Mar 6, 2023
06a0e2f
docs: "see the next section"
bholmesdev Mar 6, 2023
ad20691
chore: add numPosts as a benchmark flag
bholmesdev Mar 7, 2023
3e99783
chore: bump to minor changesets for MDX
bholmesdev Mar 7, 2023
773814b
chore: update TODO docs links
bholmesdev Mar 7, 2023
d83181d
docs: update component key naming and node instr
bholmesdev Mar 7, 2023
eac40e3
docs: redraft markdoc runtime config intro
bholmesdev Mar 7, 2023
fbe129b
Squashed commit of the following:
bholmesdev Mar 7, 2023
8631ad7
Revert "Squashed commit of the following:"
bholmesdev Mar 7, 2023
7a86989
Merge branch 'main' into markdoc-poc
bholmesdev Mar 7, 2023
822c642
feat: add mdx backwards compat to make nonbreaking
bholmesdev Mar 7, 2023
0eab2bc
chore: add comment on error code
bholmesdev Mar 7, 2023
79673ea
Revert "chore: bump to minor changesets for MDX"
bholmesdev Mar 7, 2023
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
15 changes: 15 additions & 0 deletions .changeset/breezy-cats-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'astro': patch
'@astrojs/markdoc': patch
matthewp marked this conversation as resolved.
Show resolved Hide resolved
'@astrojs/mdx': patch
bholmesdev marked this conversation as resolved.
Show resolved Hide resolved
---

Introduce the (experimental) `@astrojs/markdoc` integration. This unlocks Markdoc inside your Content Collections, bringing support for Astro and UI components in your content. This also improves Astro core internals to make Content Collections extensible to more file types in the future.

You can install this integration using the `astro add` command:

```
astro add markdoc
```

[Read the `@astrojs/markdoc` documentation](https://docs.astro.build/en/guides/integrations-guide/markdoc/) for usage instructions, and browse the [new `with-markdoc` starter](https://astro.new/with-markdoc) to try for yourself.
21 changes: 21 additions & 0 deletions examples/with-markdoc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# build output
dist/
# generated types
.astro/

# dependencies
node_modules/

# logs
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*


# environment variables
.env
.env.production

# macOS-specific files
.DS_Store
4 changes: 4 additions & 0 deletions examples/with-markdoc/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"recommendations": ["astro-build.astro-vscode"],
bholmesdev marked this conversation as resolved.
Show resolved Hide resolved
"unwantedRecommendations": []
}
11 changes: 11 additions & 0 deletions examples/with-markdoc/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "./node_modules/.bin/astro dev",
"name": "Development server",
"request": "launch",
"type": "node-terminal"
}
]
}
59 changes: 59 additions & 0 deletions examples/with-markdoc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Astro Example: Markdoc (experimental)

This starter showcases the experimental Markdoc integration.

```
npm create astro@latest -- --template with-markdoc
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/astro/tree/latest/examples/with-markdoc)
[![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/with-markdoc)

> 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun!

## 🚀 Project Structure

Inside of your Astro project, you'll see the following folders and files:
bholmesdev marked this conversation as resolved.
Show resolved Hide resolved

```
/
├── public/
├── src/
│ └── content/
└── docs/
│ └── intro.mdoc
| └── config.ts
│ └── components/
| ├── Aside.astro
│ └── DocsContent.astro
│ └── layouts/
│ └── Layout.astro
│ └── pages/
│ └── index.astro
| └── env.d.ts
├── astro.config.mjs
├── README.md
├── package.json
└── tsconfig.json
```

Markdoc (`.mdoc`) files can be used in content collections to author your Markdown content alongside Astro and server-rendered UI framework components (React, Vue, Svelte, and more). See `src/content/docs/` for an example file.

You can also apply Astro components and server-rendered UI components (React, Vue, Svelte, etc) to your Markdoc files. See `src/content/DocsContent.astro` for an example.

## 🧞 Commands

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :--------------------- | :----------------------------------------------- |
| `npm install` | Installs dependencies |
| `npm run dev` | Starts local dev server at `localhost:3000` |
| `npm run build` | Build your production site to `./dist/` |
| `npm run preview` | Preview your build locally, before deploying |
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
| `npm run astro --help` | Get help using the Astro CLI |

## 👀 Want to learn more?

Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
19 changes: 19 additions & 0 deletions examples/with-markdoc/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from 'astro/config';
import markdoc from '@astrojs/markdoc';

// https://astro.build/config
export default defineConfig({
integrations: [
markdoc({
tags: {
aside: {
render: 'Aside',
attributes: {
type: { type: String },
title: { type: String },
},
},
},
}),
],
});
17 changes: 17 additions & 0 deletions examples/with-markdoc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@example/with-markdoc",
"type": "module",
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "astro dev",
"start": "astro dev",
"build": "astro build",
"preview": "astro preview",
"astro": "astro"
},
"dependencies": {
"@astrojs/markdoc": "^0.0.0",
"astro": "^2.0.6"
}
}
13 changes: 13 additions & 0 deletions examples/with-markdoc/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/with-markdoc/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"infiniteLoopProtection": true,
"hardReloadOnChange": false,
"view": "browser",
"template": "node",
"container": {
"port": 3000,
"startScript": "start",
"node": "14"
}
}
116 changes: 116 additions & 0 deletions examples/with-markdoc/src/components/Aside.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
// Inspired by the `Aside` component from docs.astro.build
// https://github.com/withastro/docs/blob/main/src/components/Aside.astro

export interface Props {
type?: 'note' | 'tip' | 'caution' | 'danger';
title?: string;
}

const labelByType = {
note: 'Note',
tip: 'Tip',
caution: 'Caution',
danger: 'Danger',
};
const { type = 'note' } = Astro.props as Props;
const title = Astro.props.title ?? labelByType[type] ?? '';

// SVG icon paths based on GitHub Octicons
const icons: Record<NonNullable<Props['type']>, { viewBox: string; d: string }> = {
note: {
viewBox: '0 0 18 18',
d: 'M0 3.75C0 2.784.784 2 1.75 2h12.5c.966 0 1.75.784 1.75 1.75v8.5A1.75 1.75 0 0114.25 14H1.75A1.75 1.75 0 010 12.25v-8.5zm1.75-.25a.25.25 0 00-.25.25v8.5c0 .138.112.25.25.25h12.5a.25.25 0 00.25-.25v-8.5a.25.25 0 00-.25-.25H1.75zM3.5 6.25a.75.75 0 01.75-.75h7a.75.75 0 010 1.5h-7a.75.75 0 01-.75-.75zm.75 2.25a.75.75 0 000 1.5h4a.75.75 0 000-1.5h-4z',
},
tip: {
viewBox: '0 0 18 18',
d: 'M14 0a8.8 8.8 0 0 0-6 2.6l-.5.4-.9 1H3.3a1.8 1.8 0 0 0-1.5.8L.1 7.6a.8.8 0 0 0 .4 1.1l3.1 1 .2.1 2.4 2.4.1.2 1 3a.8.8 0 0 0 1 .5l2.9-1.7a1.8 1.8 0 0 0 .8-1.5V9.5l1-1 .4-.4A8.8 8.8 0 0 0 16 2v-.1A1.8 1.8 0 0 0 14.2 0h-.1zm-3.5 10.6-.3.2L8 12.3l.5 1.8 2-1.2a.3.3 0 0 0 .1-.2v-2zM3.7 8.1l1.5-2.3.2-.3h-2a.3.3 0 0 0-.3.1l-1.2 2 1.8.5zm5.2-4.5a7.3 7.3 0 0 1 5.2-2.1h.1a.3.3 0 0 1 .3.3v.1a7.3 7.3 0 0 1-2.1 5.2l-.5.4a15.2 15.2 0 0 1-2.5 2L7.1 11 5 9l1.5-2.3a15.3 15.3 0 0 1 2-2.5l.4-.5zM12 5a1 1 0 1 1-2 0 1 1 0 0 1 2 0zm-8.4 9.6a1.5 1.5 0 1 0-2.2-2.2 7 7 0 0 0-1.1 3 .2.2 0 0 0 .3.3c.6 0 2.2-.4 3-1.1z',
},
caution: {
viewBox: '-1 1 18 18',
d: 'M8.9 1.5C8.7 1.2 8.4 1 8 1s-.7.2-.9.5l-7 12a1 1 0 0 0 0 1c.2.3.6.5 1 .5H15c.4 0 .7-.2.9-.5a1 1 0 0 0 0-1l-7-12zM9 13H7v-2h2v2zm0-3H7V6h2v4z',
},
danger: {
viewBox: '0 1 14 17',
d: 'M5 .3c.9 2.2.5 3.4-.5 4.3C3.5 5.6 2 6.5 1 8c-1.5 2-1.7 6.5 3.5 7.7-2.2-1.2-2.6-4.5-.3-6.6-.6 2 .6 3.3 2 2.8 1.4-.4 2.3.6 2.2 1.7 0 .8-.3 1.4-1 1.8A5.6 5.6 0 0 0 12 10c0-2.9-2.5-3.3-1.3-5.7-1.5.2-2 1.2-1.8 2.8 0 1-1 1.8-2 1.3-.6-.4-.6-1.2 0-1.8C8.2 5.3 8.7 2.5 5 .3z',
},
};
const { viewBox, d } = icons[type];
---

<aside class={`content ${type}`} aria-label={title}>
<p class="title" aria-hidden="true">
<span class="icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox={viewBox} width={16} height={16}>
<path fill-rule="evenodd" d={d}></path>
</svg>
</span>
{title}
</p>
<section>
<slot />
</section>
</aside>

<style>
aside {
--color-base-purple: 269, 79%;
--color-base-teal: 180, 80%;
--color-base-red: 351, 100%;
--color-base-yellow: 41, 100%;

--aside-color-base: var(--color-base-purple);
--aside-color-lightness: 54%;
--aside-accent-color: hsl(var(--aside-color-base), var(--aside-color-lightness));
--aside-text-lightness: 20%;
--aside-text-accent-color: hsl(var(--aside-color-base), var(--aside-text-lightness));

border-inline-start: 4px solid var(--aside-accent-color);
padding: 1rem;
background-color: hsla(var(--aside-color-base), var(--aside-color-lightness), 0.1);
/* Indicates the aside boundaries for forced colors users, transparent is changed to a solid color */
outline: 1px solid transparent;
}

.title {
line-height: 1;
margin-bottom: 0.5rem;
font-size: 0.9rem;
letter-spacing: 0.05em;
font-weight: bold;
text-transform: uppercase;
color: var(--aside-text-accent-color);
}

.icon svg {
width: 1.5em;
height: 1.5em;
vertical-align: middle;
fill: currentcolor;
}

aside :global(a),
aside :global(a > code:not([class*='language'])) {
color: var(--aside-text-accent-color);
}

aside :global(pre) {
margin-left: 0;
margin-right: 0;
}

.tip {
--aside-color-lightness: 42%;
--aside-color-base: var(--color-base-teal);
}

.caution {
--aside-color-lightness: 59%;
--aside-color-base: var(--color-base-yellow);
}

.danger {
--aside-color-lightness: 54%;
--aside-color-base: var(--color-base-red);
}
</style>
32 changes: 32 additions & 0 deletions examples/with-markdoc/src/components/DocsContent.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
import Aside from './Aside.astro';
import type { CollectionEntry } from 'astro:content';

type Props = {
entry: CollectionEntry<'docs'>;
};

const { entry } = Astro.props;
const { Content } = await entry.render();
---

<Content
components={{
// Pass a mapping from the component name
// To an Astro or UI component import
// See your `astro.config.mjs` for
// for the Markdoc tag mapping
Aside,
}}
/>

<style is:global>
table {
margin-block: 2rem;
margin-inline: auto;
}
table td {
padding-block: 0.3rem;
padding-inline: 0.5rem;
}
</style>
9 changes: 9 additions & 0 deletions examples/with-markdoc/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineCollection, z } from 'astro:content';

const docs = defineCollection({
schema: z.object({
title: z.string(),
}),
});

export const collections = { docs };
39 changes: 39 additions & 0 deletions examples/with-markdoc/src/content/docs/intro.mdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
title: Welcome to Markdoc 👋
---

This simple starter showcases Markdoc with Content Collections. All Markdoc features are supported, including this nifty built-in `{% table %}` tag:

{% table %}
* Feature
* Supported
---
* `.mdoc` in Content Collections
* ✅
---
* Markdoc transform configuration
* ✅
---
* Astro components
* ✅
{% /table %}

{% aside title="Code Challenge" type="tip" %}

Reveal the secret message below by adding `revealSecret: true` to your list of Markdoc variables.

_Hint: Try [adding a `variables` object](https://markdoc.dev/docs/variables#global-variables) to your Markdoc config. Check the `astro.config.mjs`._

{% if $revealSecret %}

Maybe the real secret was the Rick Rolls we shared along the way.

![Rick Astley dancing](https://media.tenor.com/x8v1oNUOmg4AAAAM/rickroll-roll.gif)

{% /if %}

{% /aside %}

Check out [the `@astrojs/markdoc` integration][astro-markdoc] for complete documentation and usage examples.

[astro-markdoc]: https://docs.astro.build/en/guides/integrations-guide/markdoc/
2 changes: 2 additions & 0 deletions examples/with-markdoc/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference path="../.astro/types.d.ts" />
/// <reference types="astro/client" />
Loading