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

Url loader #66

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 All @@ -72,11 +72,11 @@
>
<span
class="desc"
v-html="theme.docFooter?.prev || 'Previous page'"

Check warning on line 75 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / build-tests (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack

Check warning on line 75 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / build-tests (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack

Check warning on line 75 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / lint (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack
/>
<span
class="title"
v-html="control.prev.text"

Check warning on line 79 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / build-tests (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack

Check warning on line 79 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / build-tests (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack

Check warning on line 79 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / lint (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack
/>
</Link>
</div>
Expand All @@ -89,11 +89,11 @@
>
<span
class="desc"
v-html="theme.docFooter?.next || 'Next page'"

Check warning on line 92 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / build-tests (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack

Check warning on line 92 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / build-tests (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack

Check warning on line 92 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / lint (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack
/>
<span
class="title"
v-html="control.next.text"

Check warning on line 96 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / build-tests (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack

Check warning on line 96 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / build-tests (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack

Check warning on line 96 in components/VPLDocFooter.vue

View workflow job for this annotation

GitHub Actions / lint (ubuntu-24.04, 20)

'v-html' directive can lead to XSS attack
/>
</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://raw.githubusercontent.com/lando/setup-lando/refs/heads/main/docs/macos.md
```

**long form**

```yaml
url-loader:
source: https://raw.githubusercontent.com/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://raw.githubusercontent.com/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://raw.githubusercontent.com/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://raw.githubusercontent.com/lando/setup-lando/refs/heads/main/docs/windows.md
content: append
frontmatter: false
```
:::
Loading
Loading