mecha-cms / mecha

Minimalist content management system.

Home Page:https://mecha-cms.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TODO: Configurable YAML Document Prefix and Suffix

taufik-nurrohman opened this issue · comments

The easiest way would be to use constants:

define("YAML\\SOH", '---');
define("YAML\\ETB", '---');
define("YAML\\EOT", '...');

Reference

  • SOH (Start of Heading): In message transmission, delimits the start of a message header. The format of this header may be defined by an applicable protocol, such as IPTC 7901 for journalistic text transmission, and it is usually terminated by STX. In Hadoop, it is often used as a field separator.
  • ETB (End of Transmission Block): Indicates the end of a transmission block of data when data are divided into such blocks for transmission purposes. If it is not in use for another purpose, IPTC 7901 recommends interpreting ETB as an end of paragraph character.
  • EOT (End of Transmission): Delimits the end of a transmitted message, which may include a header, message text and post-text footer, or even multiple texts and associated headings. May also be used to place terminals on standby. Often used on Unix to indicate end-of-file on a terminal.

This naming proposal has nothing to do with the C0 and C1 control characters specification. I just want to make a short name with a semantic meaning. The available control character names are self explanatory.

Example

Given response data as follows:

---
foo: 1
---
bar: 2
...
baz: 3

The YAML parser should interpret the data as follows:

<SOH>
foo: 1
<ETB>
bar: 2
<EOT>
baz: 3

And should give this kind of result:

[
    0 => ['foo' => 1],
    1 => ['bar' => 2],
    "\t" => 'baz: 3'
]

Why?

Most static site generators use what they call “YAML Front-Matter” to make a separation between meta-data and the contents. It is never standardized and is followed by many developers just because it is so popular.

Mecha tends to follow the original YAML document specification, that is, to declare the end of the stream with a ... marker instead of ---.

By defining these delimiters as constants, it will likely allows my users to store their page data using the YAML Front-Matter format. That is, by changing the YAML\EOT constant value into ---.