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.

Suggesting new contents.lr file format

See original GitHub issue

I think this can be implemented without a breaking change. Current format is always terminated with three dashes:

body: 

Multi-line
text content
---
title: single-line content
---
emptyAttr:
---
boolean1: yes
---

I do think this is a lot of boiler plate code espcially if most attributes are single-line. My suggestion would result it the following:

body:

Multi-line
text content
---
title: single-line content
emptyAttr:
boolean1: yes

There are three scenarios. If the line (after the colon) contains:

  1. any non-whitespace → it is considered single-line and terminated by \n and/or \r
  2. only whitespace and the following line is also whitespace → it is considered a multi-line attribute and terminated by ---
  3. only whitespace and the following line is not whitespace → the attribute is considered empty

This parsing is almost completely compatible with the current file format. In the 1. and 3. case, after a single-line attribute we simply ignore the three dashes in the following line. Case 2 hasn’t changed and is processed till the three dashes. So we could use the same parser for both, v1 and v2 content format.

However, there is one case where it might indeed break. I havent tested these, but I think they are perfectly valid as of now:

tag1: multi-line
starting after tag
---
tag2: 
multi-line
starting in the following line
---

So, in case someone has edited the content file manually and removed the double newline it would break parser v2. Luckily the UI produces the double newline already, so for almost all projects this should be fine.

We could even recover from a parsing error. In this scenario the parser would assume a new attribute on the 2nd line. If we don’t detect an attribute name (v2) or --- (v1) in the next line, then there must be something wrong with the format. So we show the faulty file to the user.

Of course there are edge cases that won’t be detected, like:

blogTitle:
Wednesday: Workshop
---

(the parser would assume Wednesday is an attribute and won’t complain)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
davidismcommented, Jul 28, 2020

Counterpoint to yours: I find the current format easy to read/parse with human eyes. Every field is guaranteed to be separated by --- and be a simple key: value. It requires zero extra parsing, as a human or with Lektor.

That said, there’s an issue opened about allowing a project to use a different parser: #751. If that gets through you could write a lektor-non-separated-config package to provide a different parser.

1reaction
relikdcommented, Jul 28, 2020

Reading through #541 and the suggestion of including files, we could even enforce single-line attributes. Each attribute that is multi-line (html, markdown, text) will automatically be outsourced into its counterpart file. Without the need of escaping --- on user input. The parser would be even simpler than it is now. One line, one attribute, split by the first colon.

As for the outsourced file, it does not need to be named anywhere. The name could be inferred by the attribute key and model description, e.g., body.md. Enabling syntax highlighting and what not. For flows they could be enumerated, flow-type.1.body.md, etc.

Thats of course only possible with a breaking change, or with the minimum required version as suggested.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use keywords in Lightroom Classic - Adobe Support
In the Create Keyword Tag dialog box, type a name for the keyword. Type synonyms for the keyword. Use commas to separate the...
Read more >
Suggest edits in Google Docs - Computer
Suggest changes to a file. On your computer, open a document at docs.google.com. Select the text you want to change. A button appears...
Read more >
Which Lightroom files do I need to back up?
Which Lightroom files do I need to back up? · The Catalog · The Previews · The Catalog Backups · The Photos ·...
Read more >
How to Organize Your Photos in Lightroom in 10 Steps
Step 1. Set Up a Folder System in Lightroom · Catalog: This is where you'll store your Lightroom catalog. You should create a...
Read more >
Best Lightroom Export Settings (For Print, Instagram & More)
Rather than export the files at 100%, select 85%. This will reduce the file size and keep perceived image quality. Some photographers even...
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