Conversation
There was a problem hiding this comment.
I really like it! Only spot I've been struggling on is whether it should be
'collections' => [
'posts' => [
'path' => 'blog/{filename}',
'extra_output' => ['markdown'],
],
],
that way if we include automatic TOC enable/disabling can be something like
'collections' => [
'posts' => [
'path' => 'blog/{filename}',
'extra_output' => ['markdown' => [ 'toc' => false ] ],
],
],
Lots of nesting, so might be best to keep output_markdown and then output_markdown => [ 'toc' => false] but been wondering commit-ing to a flat config could be more painful down the road
and if we decided to also enable it per collection item be something, on a collection's front matter we could - though maybe this something for future exploration
---
...
extra_output:
- markdown
---
tonysm
left a comment
There was a problem hiding this comment.
Nice! Looks good, only left one comment around a deprecated method
|
|
||
| $yaml_header = implode("\n", ['---', 'extends: _layouts.collection_item', 'section: content', '---']); | ||
|
|
||
| $files = $this->setupSource([ |
There was a problem hiding this comment.
I think setupSource is deprecated, right? We should use createSource instead
There was a problem hiding this comment.
Yeah, I followed the rest of the codebase. Perhaps we need to change all occurrences of setupSource in another PR, agree?
|
Thanks @gcavanunez and @tonysm! I've added the title as H1 and table of contents features. I settled on the config shape detailed in the updated PR description. Let me know what you think. |
......................................................................✓..... .......................................... ──────────────────────────────────────────────────────────────────── Laravel FIXED ................................... 118 files, 1 style issue fixed ✓ src/Handlers/CollectionItemHandler.php unary_operator_spaces, no_unused_i… )
.................✓........................✓..........✓.✓.✓.................. .........................✓...✓............. ──────────────────────────────────────────────────────────────────── Laravel FIXED .................................. 119 files, 7 style issues fixed ✓ src/Bootstrap/HandleExceptions.php fully_qualified_strict_types, unary_op… ✓ src/Container.php fully_qualified_strict_types, ordered_imports ✓ src/Events/EventBus.php fully_qualified_strict_types, ordered_imports ✓ src/Exceptions/Handler.php fully_qualified_strict_types, unary_operator_s… ✓ src/Support/helpers.php fully_qualified_strict_types, unary_operator_spac… ✓ stubs/site/bootstrap.php fully_qualified_strict_types, ordered_imports ✓ tests/TestCase.php class_definition, fully_qualified_strict_types, braces… )
................................................................✓......✓.... ............................................ ──────────────────────────────────────────────────────────────────── Laravel FIXED .................................. 120 files, 2 style issues fixed ✓ src/Handlers/CollectionItemHandler.php unary_operator_spaces, not_operato… ✓ src/Providers/CollectionServiceProvider.php ordered_imports )
8dd037a to
866d489
Compare
|
@nicodevs looks good to me. Nice work on this! 👍🏼 |
In this AI era, many websites offer a Markdown version of their pages using the same URL with a
.mdextension (like this: https://laravel.com/docs/12.x/ai-sdk.md) to make them easier for LLMs to consume.This PR adds a collection option to Jigsaw to automatically generate these
.mdfiles.Usage
In
config.php:'collections' => [ 'posts' => [ 'path' => 'blog/{filename}', + 'output_markdown' => true, ], ],This produces both
blog/my-post/index.html(orblog/my-post.html) andblog/my-post.mdfor each collection item.output_markdown=trueis in fact a shortcut of the longer config options, which are detailed below:Title as H1
By default, the title of the resource is used as the level-one heading in the generated Markdown. For this resource:
…the output will be:
# How to Install Jigsaw Hello! Today...If the user does not want this behavior, they can opt out by setting:
Table of Contents
Additionally, by default, the body headings are parsed to build a table of contents at the top of the generated Markdown. For example, given the following document:
The output will be:
If the user does not want this behavior, they can opt out by setting:
Implementation Details
When
output_markdownis enabled,CollectionItemHandlernow returns twoOutputFileinstances to the build output: the original file and a raw Markdown version.To add the title and the table of contents to the markdown we have a new class,
PlainMarkdownBuilder.No new dependencies are introduced.
Note
Note for reviewers: many of the listed “Files changed” reflect linting-only modifications.