picocms / Pico

Pico is a stupidly simple, blazing fast, flat file CMS.
http://picocms.org/
MIT License
3.81k stars 616 forks source link

MD split #659

Closed digitalinferno closed 1 year ago

digitalinferno commented 1 year ago

When I need a special style for content in my page (for example in a one-page design) I use multiple md files (_part1.md _part2.md etc) so I can put a text paragraph exactly where I need it. It's a perfect workaround, but when I need multiple pages, with multiple paragraphs... I need a lot of md files.

So it's possible to split a md file with maybe a custom tag or a specific syntax?

Something like this:

---
Title: Test
Author: Me
Template: page
Split: yes
---
### 1
lorem ipsum

### 2
dolor sit amet

So {{ "_page"|content(1) }} return lorem ipsum and {{ "_page"|content(2) }} return dolor sit amet

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two days if no further activity occurs. Thank you for your contributions! :+1:

PhrozenByte commented 1 year ago

Not out-of-the-box. As always, you could write a plugin to allow something like this. However, personally I'd recommend you to take advantage of it: Make splitting up pages into parts a conscious decision. Split pages into parts using hidden directories, i.e. the page sub/page.md could automatically include sub/_page/part1.md, sub/_page/part2.md, … You can now write your theme so that it automatically checks whether there are hidden sub/_page/*.md pages and include them accordingly, if one requested sub/page. This should be possible with pure Twig.

digitalinferno commented 1 year ago

Thanks for the hint :+1: I have already a "portfolio section" with a for cycle to automatically include projects and display a thumbnail of the project:

{% for page in pages("portfolio")|sort_by("time")|reverse if not page.hidden %}          
    ...
    <a href="{{ page.url }}">
        <img src="assets/{{ page.id }}-thumbnail.webp" alt="{{ page.title }}" />
    </a>
    ...
{% endfor %}

I was close to the right approach... :smile: