question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Included markdown file in content files

See original GitHub issue

This was originally mentioned in the comments of #439, and later I mentioned it again in #532. This is a different topic though, so it gets its own issue.

There is a common desire to in some way include a markdown file by reference in a content field of a contents.lr So instead of a markdown body field whose section in a contents.lr looks like

body:

**Some Markdown here**
and here.

The value for the body field would point to an external .md file. The ability to separate out a (large) field’s value can make it easier to maintain that field (it could be outside of a project repo, it could be “hot swappable”, etc), and break apart a large contents.lr into more conceptually digestible chunks.

This could be done for a variety of different field types, and potentially arbitrary field types, though I think it makes the most sense for multi-line string-like types.

So how do we accomplish this? An option is to allow for attachments of other various types, detected by file extension, and then allowing the ability to select attachments via the CMS. Another option is to add a way for someone to input a relative path in the CMS / contents.lr that can point to any file. Do we let users define file types in models? Do we force them? There are lots of ways this could be done and discussion is welcomed.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:4
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
nixjdmcommented, May 31, 2018

I’m not talking about treating a contents.lr as a markdown file, but more like the comment that follows the one you cite - including an external file by reference in an contents.lr. My question is, what method is best?

I realized that one way this could work is by virtue of my plugin Jinja Content. For instance, with this, you could actually reference any other file and pull it in with a standard jinja include. E.g.

body:

{% include "my_content.md" %}

This nearly works right now, but I think Lektor would need a couple small updates to https://github.com/lektor/lektor/blob/master/lektor/environment.py, and the plugin would need to add some paths to support “templates” being in the contents dir.

Some points about this approach:

  • This won’t require a ton of effort I think. I hardcoded a few things to test it quickly, and the proof of concept works.
  • Standard jinja tagging, which is nice
  • More flexible than the idea of having either markdown in contents.lr directly or included by reference, being mutually exclusive. With this, you could mix and match, or even have multiple includes in the same field.
  • I was originally envisioning some helpers in the CMS. A file select widget for instance to find and select a file. This is just coded in manually, which is kind of less friendly, but on the other hand it enforces working only in certain “template” paths, which is good. That means someone can’t reference something outside their project.

If that’s the route we take, Lektor itself would only be changed to allow the functionality by the plugin, and the plugin’s doing most of the work.

0reactions
xlotlucommented, Apr 14, 2020

That feels like to much magic, I would rather have it be explicit

Yes, it shouldn’t be auto-magic. I was thinking it could be a global setting, or per-field:

[fields.body]
type = markdown
include = true

Then we’d have a single content-type for any given format, and the only change needed to the existing types would be to give them a set of extensions to look for where appropriate. Or (also) make it explicit in the model:

[fields.body]
type = markdown
; this could be implied if any of the below are true: 
include = true
; I don't particularly like this one:
include-file = body.md
; I'd rather have the filename implied
include-extensions = md, markdown
Read more comments on GitHub >

github_iconTop Results From Across the Web

Markdown and including multiple files - Stack Overflow
Specifically, I want to create a separate markdown file with links that I call often but not always (call this B.md), then when...
Read more >
Markdown file inclusion · Paradox
The @@include block is used to include full or partial markdown files rendered into this file. @@include[my-file.md](includes/my-file.md).
Read more >
Getting Started | Markdown Guide
Markdown is a fast and easy way to take notes, create content for a website, and produce print-ready documents. It doesn't take long...
Read more >
How can a markdown file include another? - WebWorks
To include markdown files in other folders, be sure to use a path that is relative to the file that contains the include...
Read more >
Markdown Preview Include Files - Visual Studio Marketplace
Support transclusion of files within Markdown Preview · Include copyright on multiple markdown files · Include file containing important links and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found