feature: HTML to Markdown (component & routes)#235
Conversation
use slots.render to get html and transform it to markdown
|
|
||
| export const partial = true; | ||
|
|
||
| Astro.response.headers.set('Content-Type', 'text/markdown; charset=utf-8'); |
There was a problem hiding this comment.
HTML entities in the content are still encoded (< becomes < etc). This is not the cause of the ToMarkdown component as it also happens with the HTML comment below. So Astro forces this higher up I believe. Haven't been able to stop encoding or force decoding 🤷 .
|
|
||
| **Renders nested HTML content to Markdown.** | ||
|
|
||
| ## Examples |
There was a problem hiding this comment.
I wanted to write these and others as test. But while this component works in a route, I'm not able to isolate the output properly. 🤷 .
| import { datocmsCollection } from '@lib/datocms'; | ||
| import { type PageRouteForPath, getPagePath } from '@lib/routing/page'; | ||
|
|
||
| export async function getStaticPaths() { |
There was a problem hiding this comment.
Could keep this in index.astro and try to import it in index.md.astro. I like this separate file as it makes it more clear it can be used across routes. And it also obfuscated the content of index.astro a bit. So I'm happy with this.
| @@ -0,0 +1,16 @@ | |||
| --- | |||
| import ToMarkdown from '@components/ToMarkdown/ToMarkdown.astro'; | |||
| import Page from './index.astro'; | |||
There was a problem hiding this comment.
I like this pattern where the Page from index.astro can remain unmodified and this route does all the ToMarkdown magic. If a developer using Head Start doesn't need this behaviour, this index.md.astro route can simply be removed.
jurgenbelien
left a comment
There was a problem hiding this comment.
It works (apart from the html entities) and there are some changes that are IMHO beneficial to the project regardless (moving staticPaths to separate file).
I do wonder if this functionality makes sense out of the box, instead of adding it later on for a project that needs it. For starters this increases build time for every project, even if they don't use it. A developer might remove the markdown route but forget the link tag, serving erroneous alternates that might negatively impact SEO.
There was a problem hiding this comment.
Copilot reviewed 6 out of 11 changed files in this pull request and generated 3 comments.
Files not reviewed (5)
- package.json: Language not supported
- public/_headers: Language not supported
- src/components/ToMarkdown/ToMarkdown.astro: Language not supported
- src/pages/[locale]/[...path]/index.astro: Language not supported
- src/pages/[locale]/[...path]/index.md.astro: Language not supported
|
Will be replaced by #345 |
Changes
Making our HTML pages available as Markdown is of interest to some people and especially suitable for software such as LLM's. These changes make HTML content available as Markdown.
ToMarkdowncomponent to render HTML as Markdown (works both run- and build-time).[locale]/[...path]/index.md.astroroute to render matching route as Markdown (works both run- and build-time)..mdas Astro always generates.md/index.htmlfiles.See decision log entry for background.
Associated issue
N/A
How to test
/en/documentation/getting-started/.md, like/en/documentation/getting-started.md/en/demos/tables-demo.mdChecklist