swup / docs

Official swup documentation 📘
https://swup.js.org/getting-started
12 stars 35 forks source link

feat: load remote content #99

Closed hirasso closed 1 year ago

hirasso commented 1 year ago

Description

Adds a new frontmatter key content_source. If that key is present, the content will be loaded and parsed instead of the markdown file's local body content itself. For example, the A11y plugin readme now looks like this:

layout: default
title: Accessibility Plugin
description: Plugin to enhanced accessibility
parent: Plugins
nav_order: 1
permalink: /plugins/a11y-plugin/
repo_link: /a11y-plugin
content_source: https://raw.githubusercontent.com/swup/a11y-plugin/master/readme.md

The script will replace the contents of the <h1> from the plugin readmes with the title from the local frontmatter. So "Swup A11y Plugin" will become "Accessibility Plugin". Matches the menu item, matches the context of the main docs.

Checks

netlify[bot] commented 1 year ago

Deploy Preview for splendorous-kataifi-9ae281 ready!

Name Link
Latest commit b4ab67c7c7e6b0e461b4482dd74bdec5872dec04
Latest deploy log https://app.netlify.com/sites/splendorous-kataifi-9ae281/deploys/644036f340a57d0008f360e6
Deploy Preview https://deploy-preview-99--splendorous-kataifi-9ae281.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

daun commented 1 year ago

🎳

daun commented 1 year ago

How do we then trigger re-builds when a plugin has changed? Currently, we can update the MD file, now there's no visible change in the source code.

hirasso commented 1 year ago

@gmrchk is working on triggering rebuilds

gmrchk commented 1 year ago

Workflows for triggering the job are ready. Shall we replace the content for all plugins in the same PR?

Also, there is one thing that needs adjusting, and it's the "Edit this page" link. This should now lead to the repository readme instead of the file in docs, at least for these external pages?

hirasso commented 1 year ago

Workflows for triggering the job are ready. Shall we replace the content for all plugins in the same PR?

Nice! Yes!

Also, there is one thing that needs adjusting, and it's the "Edit this page" link. This should now lead to the repository readme instead of the file in docs, at least for these external pages?

Right! I'll look into that.

hirasso commented 1 year ago

An idea: Could we not make this dynamic and use the repo_link instead of the content_source key for pulling in the content? I could dynamically construct the url like this:

https://raw.githubusercontent.com/swup{{ repo_link }}/master/readme.md
hirasso commented 1 year ago

I think there could also be something like the following.

<!-- swup docs ignore-start -->
some content here...
<!-- swup docs ignore-end -->

We could cut out these comments in the eleventy... just in case we really want to exclude something from the docs site but leave it in the readme.

Sure! I would suggest we wait until we need it before implementing it. ok?

gmrchk commented 1 year ago

An idea: Could we not make this dynamic and use the repo_link instead of the content_source key for pulling in the content? I could dynamically construct the url like this:

https://raw.githubusercontent.com/swup{{ repo_link }}/master/readme.md

I think it should be fine, but I would double-check that some pages that are not plugins don't have it too.

hirasso commented 1 year ago

Only the themes. They are working just fine, as well! Now we only have to fix the typos Instalation for them as well.

hirasso commented 1 year ago

Please ignore the failing tests and look at this file: https://github.com/swup/docs/blob/feat/load_remote_content/src/docs/plugins/a11y-plugin.md

I think making the repo_link absolute and converting it for the various use cases would be the cleanest approach. Also makes it very obvious where the actual readme comes from IMO. What do you think?

daun commented 1 year ago

I think making the repo_link absolute and converting it for the various use cases would be the cleanest approach. Also makes it very obvious where the actual readme comes from IMO. What do you think?

I actually much prefer the absolute link version. It's self-explanatory and less error-prone. It does need some string-wrangling to handle bungled trailing slashes and the likes, but that's probably worth it.

hirasso commented 1 year ago

🎉