Skip to content

Commit

Permalink
Merge branch 'main' into slorber/custom-navbar-item-components-workar…
Browse files Browse the repository at this point in the history
…ound
  • Loading branch information
slorber committed Apr 29, 2022
2 parents 70ecad4 + 47d89ae commit 8f3dc5c
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 56 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const sourceToPermalink: SourceToPermalink = {

'@site/i18n/fr/docusaurus-plugin-content-docs/current/doc-localized.md':
'/fr/doc-localized',
'@site/docs/doc-localized': '/doc-localized',
'@site/docs/doc-localized.md': '/doc-localized',
};

function createMarkdownOptions(
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus-plugin-ideal-image/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"lib": ["DOM", "ES2019"],
"rootDir": "src",
"baseUrl": "src",
"outDir": "lib"
}
}
1 change: 0 additions & 1 deletion packages/docusaurus-plugin-pwa/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"lib": ["DOM", "ES2019"],
"rootDir": "src",
"baseUrl": "src",
"outDir": "lib"
}
}
3 changes: 1 addition & 2 deletions packages/docusaurus-theme-classic/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"lib": ["DOM", "ES2019"],
"module": "esnext",
"noEmit": true,
"jsx": "react-native",
"baseUrl": "src"
"jsx": "react-native"
},
"include": ["src/"]
}
1 change: 0 additions & 1 deletion packages/docusaurus-theme-search-algolia/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"compilerOptions": {
"lib": ["DOM", "ES2019"],
"rootDir": "src",
"baseUrl": "src",
"outDir": "lib"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,36 @@ The following operations are defined for [URI]s:
",
}
`;
exports[`replaceMarkdownLinks resolves absolute and relative links differently 1`] = `
{
"brokenMarkdownLinks": [
{
"contentPaths": {
"contentPath": "docs",
"contentPathLocalized": "i18n/docs-localized",
},
"filePath": "docs/intro/intro.md",
"link": "./api/classes/divine_uri.URI.md",
},
{
"contentPaths": {
"contentPath": "docs",
"contentPathLocalized": "i18n/docs-localized",
},
"filePath": "docs/intro/intro.md",
"link": "/another.md",
},
],
"newContent": "
[Relative link](/docs/another)
[Relative link 2](/docs/api/classes/uri)
[Relative link that should be absolute](./api/classes/divine_uri.URI.md)
[Absolute link](/docs/api/classes/uri)
[Absolute link from site dir](/docs/api/classes/uri)
[Absolute link that should be relative](/another.md)
[Relative link that acts as absolute](/docs/api/classes/uri)
[Relative link that acts as relative](/docs/another)
",
}
`;
30 changes: 30 additions & 0 deletions packages/docusaurus-utils/src/__tests__/markdownLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,36 @@ The following operations are defined for [URI]s:
).toMatchSnapshot();
});

it('resolves absolute and relative links differently', () => {
expect(
replaceMarkdownLinks({
siteDir: '.',
filePath: 'docs/intro/intro.md',
contentPaths: {
contentPath: 'docs',
contentPathLocalized: 'i18n/docs-localized',
},

sourceToPermalink: {
'@site/docs/intro/intro.md': '/docs/intro',
'@site/docs/intro/another.md': '/docs/another',
'@site/docs/api/classes/divine_uri.URI.md': '/docs/api/classes/uri',
},

fileString: `
[Relative link](./another.md)
[Relative link 2](../api/classes/divine_uri.URI.md)
[Relative link that should be absolute](./api/classes/divine_uri.URI.md)
[Absolute link](/api/classes/divine_uri.URI.md)
[Absolute link from site dir](/docs/api/classes/divine_uri.URI.md)
[Absolute link that should be relative](/another.md)
[Relative link that acts as absolute](api/classes/divine_uri.URI.md)
[Relative link that acts as relative](another.md)
`,
}),
).toMatchSnapshot();
});

// TODO bad
it('ignores links in HTML comments', () => {
expect(
Expand Down
14 changes: 10 additions & 4 deletions packages/docusaurus-utils/src/markdownLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
// Replace it to correct html link.
const mdLink = mdMatch.groups!.filename!;

const sourcesToTry = [
path.dirname(filePath),
...getContentPathList(contentPaths),
].map((p) => path.join(p, decodeURIComponent(mdLink)));
const sourcesToTry: string[] = [];
// ./file.md and ../file.md are always relative to the current file
if (!mdLink.startsWith('./') && !mdLink.startsWith('../')) {
sourcesToTry.push(...getContentPathList(contentPaths), siteDir);
}
// /file.md is always relative to the content path
if (!mdLink.startsWith('/')) {
sourcesToTry.push(path.dirname(filePath));
}

const aliasedSourceMatch = sourcesToTry
.map((p) => path.join(p, decodeURIComponent(mdLink)))
.map((source) => aliasedSitePath(source, siteDir))
.find((source) => sourceToPermalink[source]);

Expand Down
2 changes: 1 addition & 1 deletion website/docs/advanced/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Plugins are the building blocks of features in a Docusaurus 2 site. Each plugin

## Creating plugins {#creating-plugins}

A plugin is a function that takes two parameters: `context` and `options`. It returns a plugin instance object (or a promise). You can create plugins as functions or modules. For more information, refer to the [plugin method references section](./api/plugin-methods/README.md).
A plugin is a function that takes two parameters: `context` and `options`. It returns a plugin instance object (or a promise). You can create plugins as functions or modules. For more information, refer to the [plugin method references section](../api/plugin-methods/README.md).

### Function definition {#function-definition}

Expand Down
2 changes: 1 addition & 1 deletion website/docs/api/plugins/plugin-google-gtag.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Most Docusaurus users configure this plugin through the preset options.
// Plugin Options: @docusaurus/plugin-google-gtag

const config = {
trackingID: '141789564',
trackingID: 'G-226F0LR9KE',
anonymizeIP: true,
};
```
39 changes: 0 additions & 39 deletions website/docs/guides/docs/docs-markdown-features.mdx

This file was deleted.

52 changes: 52 additions & 0 deletions website/docs/guides/markdown-features/markdown-features-links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
id: links
description: Links to other pages in Markdown
slug: /markdown-features/links
---

# Markdown links

There are two ways of adding a link to another page: through a **URL path** and a **file path**.

```md
- [URL path to another document](./installation)
- [file path to another document](./installation.md)
```

URL paths are unprocessed by Docusaurus, and you can see them as directly rendering to `<a href="./installation">`, i.e. it will be resolved according to the page's URL location, rather than its file-system location.

If you want to reference another Markdown file **included by the same plugin**, you could use the relative path of the document you want to link to. Docusaurus' Markdown loader will convert the file path to the target file's URL path (and hence remove the `.md` extension).

For example, if you are in `docs/folder/doc1.md` and you want to reference `docs/folder/doc2.md`, `docs/folder/subfolder/doc3.md` and `docs/otherFolder/doc4.md`:

```md title="docs/folder/doc1.md"
I am referencing a [document](doc2.md).

Reference to another [document in a subfolder](subfolder/doc3.md).

[Relative document](../otherFolder/doc4.md) referencing works as well.
```

Relative file paths are resolved against the current file's directory. Absolute file paths, on the other hand, are resolved relative to the **content root**, usually `docs/`, `blog/`, or [localized ones](../../i18n/i18n-tutorial.md) like `i18n/zh-Hans/plugin-content-docs/current`.

Absolute file paths can also be relative to the site directory. However, beware that links that begin with `/docs/` or `/blog/` are **not portable** as you would need to manually update them if you create new doc versions or localize them.

```md
You can write [links](/otherFolder/doc4.md) relative to the content root (`/docs/`).

You can also write [links](/docs/otherFolder/doc4.md) relative to the site directory, but it's not recommended.
```

Using relative _file_ paths (with `.md` extensions) instead of relative _URL_ links provides the following benefits:

- Links will keep working on the GitHub interface and many Markdown editors
- You can customize the files' slugs without having to update all the links
- Moving files around the folders can be tracked by your editor, and some editors may automatically update file links
- A [versioned doc](../docs/versioning.md) will link to another doc of the exact same version
- Relative URL links are very likely to break if you update the [`trailingSlash` config](../../api/docusaurus.config.js.md#trailing-slash)

:::warning

Markdown file references only work when the source and target files are processed by the same plugin instance. This is a technical limitation of our Markdown processing architecture and will be fixed in the future. If you are linking files between plugins (e.g. linking to a doc page from a blog post), you have to use URL links.

:::
2 changes: 1 addition & 1 deletion website/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ my-website
### Project structure rundown {#project-structure-rundown}

- `/blog/` - Contains the blog Markdown files. You can delete the directory if you've disabled the blog plugin, or you can change its name after setting the `path` option. More details can be found in the [blog guide](blog.mdx)
- `/docs/` - Contains the Markdown files for the docs. Customize the order of the docs sidebar in `sidebars.js`. You can delete the directory if you've disabled the docs plugin, or you can change its name after setting the `path` option. More details can be found in the [docs guide](./guides/docs/docs-markdown-features.mdx)
- `/docs/` - Contains the Markdown files for the docs. Customize the order of the docs sidebar in `sidebars.js`. You can delete the directory if you've disabled the docs plugin, or you can change its name after setting the `path` option. More details can be found in the [docs guide](./guides/docs/docs-introduction.md)
- `/src/` - Non-documentation files like pages or custom React components. You don't have to strictly put your non-documentation files here, but putting them under a centralized directory makes it easier to specify in case you need to do some sort of linting/processing
- `/src/pages` - Any JSX/TSX/MDX file within this directory will be converted into a website page. More details can be found in the [pages guide](guides/creating-pages.md)
- `/static/` - Static directory. Any contents inside here will be copied into the root of the final `build` directory
Expand Down
2 changes: 1 addition & 1 deletion website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const sidebars = {
],
},
'guides/docs/versioning',
'guides/docs/markdown-features',
'guides/docs/multi-instance',
],
},
Expand All @@ -81,6 +80,7 @@ const sidebars = {
'guides/markdown-features/headings',
'guides/markdown-features/inline-toc',
'guides/markdown-features/assets',
'guides/markdown-features/links',
'guides/markdown-features/plugins',
'guides/markdown-features/math-equations',
'guides/markdown-features/head-metadata',
Expand Down
Binary file added website/src/data/showcase/raspisuite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added website/src/data/showcase/svix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions website/src/data/users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1330,6 +1330,15 @@ const Users: User[] = [
source: 'https://github.com/questdb/questdb.io',
tags: ['opensource', 'favorite', 'design', 'large'],
},
{
title: 'RaspiSuite',
description:
'A suite of mobile apps to leverage the full potential of your Raspberry Pi effortlessly.',
preview: require('./showcase/raspisuite.png'),
website: 'https://raspisuite.com',
source: null,
tags: ['design', 'product'],
},
{
title: 'Rivalis',
description:
Expand Down Expand Up @@ -1801,6 +1810,14 @@ const Users: User[] = [
source: 'https://github.com/supabase/supabase/tree/master/web',
tags: ['opensource', 'favorite', 'design', 'large', 'product'],
},
{
title: 'Svix',
description: 'Webhooks as a Service',
preview: require('./showcase/svix.png'),
website: 'https://docs.svix.com/',
source: 'https://github.com/svix/svix-docs',
tags: ['opensource', 'product'],
},
{
title: 'Synergies',
description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Plugins are the building blocks of features in a Docusaurus 2 site. Each plugin

## Creating plugins {#creating-plugins}

A plugin is a function that takes two parameters: `context` and `options`. It returns a plugin instance object (or a promise). You can create plugins as functions or modules. For more information, refer to the [plugin method references section](./api/plugin-methods/README.md).
A plugin is a function that takes two parameters: `context` and `options`. It returns a plugin instance object (or a promise). You can create plugins as functions or modules. For more information, refer to the [plugin method references section](../api/plugin-methods/README.md).

### Function definition {#function-definition}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Plugins are the building blocks of features in a Docusaurus 2 site. Each plugin

## Creating plugins {#creating-plugins}

A plugin is a function that takes two parameters: `context` and `options`. It returns a plugin instance object (or a promise). You can create plugins as functions or modules. For more information, refer to the [plugin method references section](./api/plugin-methods/README.md).
A plugin is a function that takes two parameters: `context` and `options`. It returns a plugin instance object (or a promise). You can create plugins as functions or modules. For more information, refer to the [plugin method references section](../api/plugin-methods/README.md).

### Function definition {#function-definition}

Expand Down

0 comments on commit 8f3dc5c

Please sign in to comment.