Opened on 10/03/2016 at 06:30:15 PM

Closed on 05/01/2018 at 06:45:31 PM

#4488 closed change (fixed)

Support JSON page front matter

Reported by: juliandoucette Assignee: rhowell
Priority: P4 Milestone:
Module: Sitescripts Keywords:
Cc: kvas, saroyanm, fhd, sebastian Blocked By: #4491
Blocking: Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

https://codereview.adblockplus.org/29516687

Description (last modified by kvas)

Background

Our CMS page front matter format supports key=value syntax.

Although this is effective, it is inconvenient because this format does not support arrays or objects.

What to change

Implement support for JSON format front matter (without breaking backwards compatibility).

Examples

These should work with/without HTML comments:

Original / Backwards compatible

<!--
title = Awesome page
description = Awesome description
image_url = /img/awesome.jpg
image_type = image/jpg
image_width = 1024
image_height = 768
image_alt = Awesome image
-->

With this front matter the variables title, description, image_url, image_type, etc. become available to use in the evaluated expressions inside of the page.

JSON

<!-- {
  "title": "Awesome page",
  "description": "Awesome description",
  "image": {
    "url": "/img/awesome.jpg",
    "type": "image/jpg",
    "width": "1024",
    "height": "768",
    "alt": "Awesome image"
  },
  "tags": ["awesome", "news"]
} -->

With this front matter the variables title, description, image['url'], image['type'], tags[0], etc. become available to use in the evaluated expressions inside of the page.

Attachments (0)

Change History (31)

comment:1 Changed on 10/03/2016 at 06:31:01 PM by juliandoucette

  • Summary changed from Support JSON front matter to Support JSON front matter on CMS pages

comment:2 Changed on 10/03/2016 at 06:31:33 PM by juliandoucette

  • Summary changed from Support JSON front matter on CMS pages to Support JSON front matter in CMS pages

comment:3 Changed on 10/04/2016 at 08:23:14 AM by juliandoucette

  • Description modified (diff)

comment:4 Changed on 10/04/2016 at 11:16:11 AM by trev

By surrounding front matter JSON in a <script type="application/json"> tag

As if JSON alone wasn't enough syntactic overhead already :-)

If you are worried about editors I would suggest going with HTML comments: <!-- ... -->. Positive side-effect: this syntax doesn't suggest that the block will be part of the output.

comment:5 Changed on 10/04/2016 at 11:59:08 AM by juliandoucette

If you are worried about editors I would suggest going with HTML comments: <!-- ... -->. Positive side-effect: this syntax doesn't suggest that the block will be part of the output.

Good idea.

comment:6 Changed on 10/04/2016 at 12:00:06 PM by juliandoucette

  • Description modified (diff)

comment:7 Changed on 10/04/2016 at 12:04:03 PM by juliandoucette

  • Description modified (diff)

comment:8 Changed on 10/04/2016 at 12:08:26 PM by trev

  • Description modified (diff)

comment:9 Changed on 10/04/2016 at 03:57:18 PM by sebastian

  • Cc sebastian added

FWIW, I consider supporting JSON for the values here, and surrounding the block by HTML comments, two separate issues. Can we please split this issue up?

comment:10 follow-up: Changed on 10/04/2016 at 04:00:41 PM by juliandoucette

FWIW, I consider supporting JSON for the values here, and surrounding the block by HTML comments, two separate issues. Can we please split this issue up?

Yes.

comment:11 in reply to: ↑ 10 Changed on 10/04/2016 at 04:07:50 PM by juliandoucette

FWIW, I consider supporting JSON for the values here, and surrounding the block by HTML comments, two separate issues. Can we please split this issue up?

Done.

https://issues.adblockplus.org/ticket/4491#ticket

comment:12 Changed on 10/04/2016 at 04:10:59 PM by juliandoucette

  • Description modified (diff)
  • Summary changed from Support JSON front matter in CMS pages to Support JSON page front matter

comment:13 Changed on 10/04/2016 at 04:12:15 PM by juliandoucette

  • Description modified (diff)

comment:14 Changed on 10/04/2016 at 04:15:41 PM by juliandoucette

  • Description modified (diff)

comment:15 Changed on 10/04/2016 at 04:41:52 PM by sebastian

Can you add some examples, how the new syntax would look like (also one considering the backwards compatibility case)?

comment:16 Changed on 10/04/2016 at 05:27:43 PM by juliandoucette

  • Description modified (diff)

comment:17 follow-up: Changed on 10/04/2016 at 05:38:31 PM by juliandoucette

Can you add some examples, how the new syntax would look like (also one considering the backwards compatibility case)?

Done.

NOTE: As I mentioned in the last frontend developer meeting, I think this should be a low priority compared to other issues (EG: separating the front matter from the content) because we rarely need page specific arrays/objects and it is relatively easy to work around. I imagine this becoming a priority if we decide to go forward with building a WYSIWYG tool. (I got this idea because I prototyped an offline WYSIWYG HTML editor using NodeJS + Electron in my spare time a few weekends ago.)

Last edited on 10/04/2016 at 05:41:54 PM by juliandoucette

comment:18 Changed on 10/04/2016 at 05:44:20 PM by juliandoucette

  • Description modified (diff)

comment:19 in reply to: ↑ 17 ; follow-up: Changed on 10/04/2016 at 06:29:48 PM by sebastian

I actually thought we are just going to use JSON for the values (e.g.title = "Awesome page"). That way it would easier to migrate from the previous format, and the implementation could share more code (basically we would just interpret the value as a string if it doesn't parse as JSON). I wouldn't insist though, but I guess it's good that I asked for an example, because it wasn't completely clear from the description. However, if we use the syntax that you suggest, it might make sense to merge #4491 back into this issue, and use the presence/absence of <!-- to indicate which format is used.

Replying to juliandoucette:

NOTE: As I mentioned in the last frontend developer meeting, I think this should be a low priority compared to other issues (EG: separating the front matter from the content)

Wait, do you imply that you don't want to have that data structure in the pages/* files in the first place? Otherwise, I'm not sure what you mean there. But if I understand correctly, I guess there is not much of a point to change the format here, if we are going to move that data structure somewhere else anyway.

Last edited on 10/04/2016 at 06:33:06 PM by sebastian

comment:20 in reply to: ↑ 19 ; follow-up: Changed on 10/04/2016 at 07:02:35 PM by juliandoucette

However, if we use the syntax that you suggest, it might make sense to merge #4491 back into this issue, and use the presence/absence of <!-- to indicate which format is used.

I disagree. The background reasoning in #4491 applies to the old format too.

Wait, do you imply that you don't want to have that data structure in the pages/* files in the first place? Otherwise, I'm not sure what you mean there. But if I understand correctly, I guess there is not much of a point to change the format here, if we are going to move that data structure somewhere else anyway.

I didn't intend to imply that.

  • It's obvious that we should support a better front matter format (EG: JSON, YAML, INI)
  • But we don't need to yet because we can use long_names_with_underscores_and_numbers and Jinja2 variables in most cases
Last edited on 10/04/2016 at 07:03:41 PM by juliandoucette

comment:21 in reply to: ↑ 20 Changed on 10/04/2016 at 07:14:34 PM by sebastian

Replying to juliandoucette:

I disagree. The background reasoning in #4491 applies to the old format too.

Sure, but we need a way to distinguish both formats, and I suppose there is no reason to use HTML comments, but not the JSON syntax, once both is supported. But never mind, it seems there are also other ways to detect JSON here.

I didn't intend to imply that.

So, what do you mean by "separating the front matter from the content"?

comment:22 Changed on 10/04/2016 at 07:50:41 PM by juliandoucette

Sure, but we need a way to distinguish both formats

JSON starts with "{"

and I suppose there is no reason to use HTML comments, but not the JSON syntax, once both is supported.

We would use HTML comments to separate the front matter from the content in the code so that they are ignored by editor formatting, linters, and HTML/Markdown previews (EG: Packages -> Markdown Preview in Atom).

So, what do you mean by "separating the front matter from the content"?

Not separated

title=Awesome page
<h1>Awesome page

Separated

<!--
title=Awesome page
-->
<h1>Awesome page</h1>
Last edited on 10/04/2016 at 07:51:34 PM by juliandoucette

comment:23 Changed on 10/04/2016 at 08:00:23 PM by sebastian

  • Priority changed from Unknown to P4
  • Ready set

comment:24 Changed on 07/18/2017 at 12:23:02 PM by rhowell

  • Owner set to rhowell

comment:25 Changed on 08/09/2017 at 11:16:21 PM by rhowell

  • Description modified (diff)

comment:26 Changed on 08/10/2017 at 06:20:16 PM by jsonesen

  • Blocked By 4491 added

comment:27 Changed on 08/16/2017 at 05:52:25 PM by kvas

  • Description modified (diff)

Based on an IRC conversation with Julian, I've updated the issue to make it clear that not interpretation should be performed on JSON metadata other than JSON decoding.

comment:28 Changed on 12/21/2017 at 11:29:03 AM by fhd

  • Cc trev removed

comment:29 Changed on 03/14/2018 at 02:37:53 AM by sebastian

  • Review URL(s) modified (diff)
  • Status changed from new to reviewing

comment:30 Changed on 05/01/2018 at 02:52:39 PM by abpbot

A commit referencing this issue has landed:
Issue 4488 - Add support for JSON page front matter

comment:31 Changed on 05/01/2018 at 06:45:31 PM by rhowell

  • Resolution set to fixed
  • Status changed from reviewing to closed

Add Comment

Modify Ticket

Change Properties
Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from rhowell.
 
Note: See TracTickets for help on using tickets.