Skip to content

Commit

Permalink
Merge pull request #69 from mrjvs/feat-expose-shiki
Browse files Browse the repository at this point in the history
Expose Shiki and Remark
  • Loading branch information
mrjvs authored Jun 8, 2024
2 parents f8a944d + 6d07490 commit bd62db3
Show file tree
Hide file tree
Showing 19 changed files with 194 additions and 98 deletions.
4 changes: 2 additions & 2 deletions apps/create-guider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neato/create-guider",
"version": "1.0.0",
"version": "1.0.1",
"description": "Beautiful documentation sites, without all the hassle",
"main": "./entry.js",
"type": "module",
Expand Down Expand Up @@ -37,7 +37,7 @@
"scripts": {
"build": "tsup",
"dev": "tsup --watch --onSuccess 'node dist/index.js'",
"lint": "eslint .",
"lint": "eslint src",
"lint:fix": "eslint --fix .",
"typecheck": "tsc --noEmit"
},
Expand Down
25 changes: 14 additions & 11 deletions apps/create-guider/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { cancel, intro, outro, spinner, text } from '@clack/prompts';
import { copy, rename } from 'fs-extra';
import { assertCancel } from './utils/prompts';
import { exists } from './utils/files';
import fs from "fs-extra";
import path from "path";
import { fileURLToPath } from 'url';

const distPath = path.dirname(fileURLToPath(import.meta.url));
const cliRoot = path.join(distPath, "../");
const mainTemplateDir = path.join(cliRoot, "templates/main");
const cliRoot = path.join(distPath, '../');
const mainTemplateDir = path.join(cliRoot, 'templates/main');

const s = spinner();
intro(`@neato/create-guider`);
Expand All @@ -17,19 +17,22 @@ const projectName = await text({
placeholder: 'my-docs',
validate(value) {
if (!/\.?[A-Za-z0-9 _-]+/g.test(value))
return "Cannot contain special characters";
return 'Cannot contain special characters';
},
});
assertCancel(projectName);

const projectDir = "./" + projectName.toString()
const projectDir = `./${projectName.toString()}`;
if (await exists(projectDir)) {
cancel("A file or folder with that name already exists");
cancel('A file or folder with that name already exists');
}

s.start('Creating files');
await fs.copy(mainTemplateDir, projectDir);
await fs.rename(path.join(projectDir, "_gitignore"), path.join(projectDir, ".gitignore"));
s.stop('Created files')
await copy(mainTemplateDir, projectDir);
await rename(
path.join(projectDir, '_gitignore'),
path.join(projectDir, '.gitignore'),
);
s.stop('Created files');

outro(`Enjoy your new documentation!`);
2 changes: 1 addition & 1 deletion apps/create-guider/templates/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"lint": "next lint"
},
"dependencies": {
"@neato/guider": "^1.0.3",
"@neato/guider": "^1.1.0",
"next": "^14.2.3",
"react": "^18.3.1",
"react-dom": "^18.3.1"
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"eslintConfig": {
"extends": [
"@repo/eslint-config"
]
],
"ignorePatterns": ["out/**/*", ".next/**/*"]
},
"prettier": "@repo/prettier-config",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/pages/docs/config/api/errors.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Error handling

Configuration loading has some potentionally confusing error handling.
By default, it will use the "pretty" assertion mode. This mode **will call process.exit(1)** instead of throwing errors. That means that you aren't able to catch it with a try-catch block.
By default, it will use the "pretty" assertion mode. **This "pretty" mode will call process.exit(1)** instead of throwing errors. That means that you aren't able to catch it with a try-catch block.

## The modes
- `pretty` Log the errors in pretty formatting and colors, then exit the process.
Expand Down
8 changes: 4 additions & 4 deletions apps/docs/pages/docs/config/api/utils.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Some helpers that can help you make configuration easier.

## `zodCoercedBoolean()`

Since `zod` boolean coercion is just doing `Boolean(value)`. You get weird cases like these:
Since `z.coerce.boolean()` is just doing `Boolean(value) under the hood. You get weird cases like these:
- `z.coerce.boolean().parse("true"); // => true`;
- `z.coerce.boolean().parse("false"); // => true`;
- `z.coerce.boolean().parse("yes"); // => true`;
Expand All @@ -14,9 +14,9 @@ Since `zod` boolean coercion is just doing `Boolean(value)`. You get weird cases
If you use `zodCoercedBoolean()` instead of `z.boolean()`, things will be more as you expect them to be.
Here is a list of valid values, these are checked while ignoring casing (if its a string):
- `"true"` -> `true`
- `"false"` -> `false`
- `"yes"` -> `true`
- `"no"` -> `true`
- `true` -> `true`
- `false` -> `true`
- `"false"` -> `false`
- `"no"` -> `false`
- `false` -> `false`
- any other values will be read as `false`
1 change: 0 additions & 1 deletion apps/docs/pages/docs/config/guide/basic-example.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ See the code snippet below for a usual setup in projects
.addFromFile(".env") // loads PORT=8080 from file
.addFromFile(".json") // loads { "port": 8080 } from file
.addZodSchema(schema) // validates the loaded data to make sure it follow the schema
.freeze() // freezes the object so no changes can be made at runtime
.load(); // this returns the fully type configuration (type infered from schema)
```
</CodeGroup.Code>
Expand Down
56 changes: 56 additions & 0 deletions apps/docs/pages/docs/guider/api-reference/setup/guider.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# `guider()`

This function is the way you inject Guider into NextJS. You can use its options
to change how Guider behaves in the compile step.


## Example

```tsx title="/next.config.mjs"
import { guider } from "@neato/guider";

const withGuider = guider({
themeConfig: './theme.config.tsx',
});

export default withGuider({
output: 'export',
});
```


## Reference

```tsx
function guider(options);
```

<Field title="options" type="DirectoryOptions" required>
Options for the redirect.

<Field.Properties defaultOpen>
<Field title="themeConfig" type="string" required>
The location of the theme file, the theme file is used to configure almost everything about guider.
</Field>
<Field title="extraRemarkPlugins" type="RemarkPlugin[]">
A list where you can specify [remark plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md) to use on top of the default list of plugins.

Use it to add new features to your markdown files.
</Field>
<Field title="remarkPlugins" type="RemarkPlugin[]">
A list where you can specify [remark plugins](https://github.com/remarkjs/remark/blob/main/doc/plugins.md) to use **instead of the default Guider plugins**.

Use it to overwrite how markdown parsing works. **Be aware that this will disable a lot of the default features of Guider, use at your own risk.** Use `extraRemarkPlugins` instead if you want to add extra plugins without breaking existing functionality.
</Field>
<Field title="extraShikiTransformers" type="ShikiTransformer[]">
A list where you can specify [Shiki transformers](https://shiki.style/guide/transformers) to use on top of the default transformers.

Use it to add new features to syntax highlighting in codeblocks.
</Field>
<Field title="shikiTransformers" type="ShikiTransformer[]">
A list where you can specify [Shiki transformers](https://shiki.style/guide/transformers) to use **instead of the default Guider transformers**.

Use it to overwrite how syntax highlighting works in Guider. **Be aware that this will disable a lot of the default features of Guider, use at your own risk.** Use `extraShikiTransformers` instead if you want to add extra transformers without breaking existing functionality.
</Field>
</Field.Properties>
</Field>
16 changes: 0 additions & 16 deletions apps/docs/pages/showcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { Showcase } from 'components/showcase-layout';
import type { ShowcaseTag, ShowcaseType } from 'components/showcase-card';
import { ShowcaseCard, ShowcaseCardContainer } from 'components/showcase-card';
import pretendoImg from 'public/showcases/pretendo.png';
import mwAccountImg from 'public/showcases/movie-web-account.png';
import mwDocsImg from 'public/showcases/movie-web-docs.png';

const showcases: ShowcaseType[] = [
{
Expand All @@ -15,20 +13,6 @@ const showcases: ShowcaseType[] = [
imageUrl: pretendoImg.src,
tags: ['guider'],
},
{
title: 'movie-web backend',
description: 'Uses Config for their account service.',
href: 'https://github.com/movie-web/backend/',
imageUrl: mwAccountImg.src,
tags: ['config'],
},
{
title: 'movie-web docs',
description: 'Uses Guider for their documentation',
href: 'https://github.com/movie-web/docs/',
imageUrl: mwDocsImg.src,
tags: ['guider'],
},
];

export default function ShowcasePage() {
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ module.exports = {
tailwindcss: {},
autoprefixer: {},
},
}
};
Binary file removed apps/docs/public/showcases/movie-web-account.png
Binary file not shown.
Binary file removed apps/docs/public/showcases/movie-web-docs.png
Binary file not shown.
2 changes: 2 additions & 0 deletions apps/docs/theme.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ export default defineTheme([
link('Layout settings', gdApi('/theme/settings')),
]),

group('Setup', [link('guider()', gdApi('/setup/guider'))]),

group('_meta.json', [
link('Structure of _meta.json', gdApi('/meta/structure')),
]),
Expand Down
9 changes: 7 additions & 2 deletions packages/guider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neato/guider",
"version": "1.0.3",
"version": "1.1.0",
"description": "Beautiful documentation sites, without all the hassle",
"main": "./dist/index.js",
"type": "module",
Expand Down Expand Up @@ -51,7 +51,12 @@
"eslintConfig": {
"extends": [
"@repo/eslint-config"
]
],
"ignorePatterns": ["dist/**/*", "style.css"],
"rules": {
"import/no-named-as-default": "off",
"import/no-named-as-default-member": "off"
}
},
"prettier": "@repo/prettier-config",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/guider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function guider(initConfig: GuiderInitConfig) {
...initConfig,
};
const guiderPlugin = new GuiderPlugin(guiderConfig);
const searchPlugin = new GuiderSearchPlugin();
const searchPlugin = new GuiderSearchPlugin(guiderConfig);

function withGuider(nextConfig: NextConfig = {}): NextConfig {
const extraWatchers = new ExtraWatchWebpackPlugin({
Expand Down
27 changes: 27 additions & 0 deletions packages/guider/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
import type { ShikiTransformer } from 'shiki';
import type { PluggableList } from 'unified';

export type GuiderInitConfig = {
/**
* The location of the theme config
*/
themeConfig: string;

/**
* Extra shiki transformers added to syntax highlighted code
*/
extraShikiTransformers?: ShikiTransformer[];

/**
* Replaces all shiki transformers added to syntax highlighted code
*/
shikiTransformers?: ShikiTransformer[];

/**
* Extra remark plugins added to markdown parsing
*/
extraRemarkPlugins?: PluggableList;

/**
* Replaces all remark plugins added to markdown parsing
* NOTE: This disables and breaks a lot of features of Guider, use at your own risk.
*/
remarkPlugins?: PluggableList;
};
6 changes: 5 additions & 1 deletion packages/guider/src/webpack/loader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ async function loader(
if (directories.pagesDir) context.addContextDependency(directories.pagesDir);

if (type === 'virtual') return virtualLoader(getGuiderPluginCache());
if (type === 'mdx') return (await mdLoader(source)).script;
if (type === 'mdx') {
if (!guiderConfig)
throw new Error('Could not read config for markdown loader');
return (await mdLoader(source, guiderConfig)).script;
}

throw new Error(`Loader used with incorrect type (${type})`);
}
Expand Down
Loading

0 comments on commit bd62db3

Please sign in to comment.