lektor / lektor

The lektor static file content management system

Home Page:https://www.getlektor.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Need a recommendation of how to include an external .md file and extract information from it for model fields.

4l1fe opened this issue · comments

For the reason that i have a knowledge base consisting of many .md files i would like to integrate them with the lektor's Admin UI and its build system.

Such the conntection would allow me to modify the source files in the knowledge base by editors i prefer to use and bring those changes to the final built artifacts.

Moreover, i would like to dynamically extract information from the source files and use it in templates:

  • extract title from .md header 1
  • extract slug from .md header 1
  • extract tags from .md text
  • extract Front Matter
  • Also, some information in the source files content must be removed, for example internal markdown links to other source files.

At the moment i'm not well experienced of using Lektor. I suppose a special model should be created with one field and, while building artifacts, process .md content for what i listed.

[model]
name = External MD File Model

[fields.external_md]`
label = external_md
type = string  # PosixPath here

Is it possible to achieve that? Should i start with customizing BuildProgram or making a plugin?
Any recommendations are welcome.

There is probably more than one reasonable way to do what you want.

As a start, you might look at how the individual plugin showcase pages are generated on the Lektor website (source code at https://github.com/lektor/lektor-website/). Each plugin page is generated by fetching the plugin distribution metadata from PyPI.

Here's the contents.lr for a particular plugin. That renders to this.
There's a custom plugin in packages/project_data that registers a jinja global function, project_data, that fetches the distribution data from PyPI. That function is used by templates/plugin.html to render the final plugin page.

I think that a similar approach would probably work in your case. That is: implement a plugin that registers a jinja global function that can be used to read and process what you want from your source .md files.