nb-sdouglas

lr-notebook/


File indexes

2016-05-12

Files and FileTypes

Background

I'd like to lr-notebook to index attachments by type, and display them on a pages like /files/json or /files/pdf. Rather than just indexing by file extension, I'd like to create my own custom groups of file extensions (e.g. images = .jpg, .png, gif; documents = .doc, .pages, .pdf).

This is somewhat like what Lektor does with attachment types: https://www.getlektor.com/docs/content/attachments/

Approach

files.ini

The first thing we need is a files.ini model. This will correspond to a content subfolder files which can just contain an empty contents.lr.

[model]
name = Files
label = Files
hidden = yes
protected = yes

[children]
model = filetype

filetype.ini

Next we need a filetype model.

[model]
name = Filetype
label = {{this.name}}
hidden = yes

[fields.name]
label = Name
type = string

[fields.extensions]
label = Extensions
type = strings

[children]
replaced_with = site.query('/projects')