Mecha CMS

Updates.

Migration Guide

Author: Taufik Nurrohman · 48 Views

Tweet

Migrating from version 1.x.x to version 2.x.x.

This page describes about how to make your old pages becomes readable by the second generation of Mecha. On this page, you will see some comparisons between Mecha version 1.x.x with Mecha version 2.x.x —in the hope that you can make some adjustments based on their similarities.

Pages 

  • Store the static pages in lot\page folder.
  • Store the blog pages (articles) in lot\page\article folder.

Version 1.x.x 

Title: Page Title
Description: "Page description."
Author: Taufik Nurrohman
Content Type: Markdown
Fields: {"foo":"bar","baz":1}

====

Version 2.x.x 

---
title: Page Title
description: Page description.
author: Taufik Nurrohman
type: Markdown
...

In version 2.x.x, you can create custom fields as separate files named as the field key with extension data, stored in a folder with the same name as the page name, without the file extension (the page state). Here, custom fields value will becomes the file content:

lot\
 └── page\
     ├── page-slug\
     │   ├── foo.data ← contains `bar`
     │   └── bar.data ← contains `1`
     └── page-slug.page

Custom Fields 

As described in the previous section, this is the difference between version 1.x.x and 2.x.x in calling the custom field data:

Version 1.x.x 

echo $page->fields->foo;
echo $page->fields->bar;

Version 2.x.x 

echo $page->foo;
echo $page->bar;

Info: You can revert to the old behavior of Mecha by storing the custom fields data as JSON and save it to a file named as fields.data instead:

lot\
 └── page\
     ├── page-slug\
     │   └── fields.data
     └── page-slug.page

Contents of fields.data:

{"foo":"bar","baz":1}

To call the custom fields:

$page->fields = (object) $page->fields;
echo $page->fields->foo;
echo $page->fields->bar;

Custom CSS and JavaScript 

Version 1.x.x 

<style>
body {
  background-color: #ffa;
  color: #000;
}
</style>

====

<script>
(function() {
  window.addEventListener("load", function() {
    console.log('Loaded!');
  }, false);
})();
</script>

Version 2.x.x 

Split your custom CSS and JavaScript data by ==== so that you will have two parts of the fields:

  • css.data

    <style>
    body {
     background-color: #ffa;
     color: #000;
    }
    </style>
  • js.data

    <script>
    (function() {
     window.addEventListener("load", function() {
       console.log('Loaded!');
     }, false);
    })();
    </script>

Store them in folder that has relationship with the page:

lot\
 └── page\
     ├── page-slug\
     │   ├── css.data ← contains the first part
     │   └── js.data ← contains the second part
     └── page-slug.page

Time and Tags 

Version 1.x.x 

Prior to version 2.x.x, time and tags data are stored in the file name, following the slug data:

2017-01-02-12-33-03_1,2,3,11_page-slug.txt

Version 2.x.x 

In this version, time and tags data are removed from the file name. However, the time data will remain attached to the page object with a value that is automatically created based on the current file modification time when you don’t set it explicitly. To set a hard–coded time data, you need to add time property to the page header. This also applies to kind (tags data):

---
title: Page Title
description: Page description.
author: Taufik Nurrohman
type: Markdown
time: 2017-01-02 12:33:03
kind: [1,2,3,11]
...

Related: Tags

Note: It is highly recommended to set the time and kind data in a separated field files because those fields data are commonly used to sort the pages. Reading embedded fields value in the page file is fairly slow, therefore, Mecha sets a higher priority on reading separated fields data instead of embedded fields data. In the case of reading page property individually, Mecha will first seek for a separated field file from the page. When the desired field can be found, Mecha will only read that field and then cancel the process of reading the entire content of that page file:

lot\
 └── page\
     ├── page-slug\
     │   ├── kind.data
     │   └── time.data
     └── page-slug.page

Info: The default shield uses slug to set the $key value in the sort() method of Anemon class, and they are sorted ascending. To sort the page listing descending by time, go to lot\shield\document\state\config.php then replace the sort value like this:

[
    // sort descending by the `time` field
    'sort' => [-1, 'time']
]

Shortcodes 

In this version, shortcode is renamed into block. This change has been made to generalize two things: the shortcode itself and the previously created plugin called snippet.

Version 1.x.x 

Prior to version 2.x.x, blocks are enclosed with curly brackets:

{‌{‌block‌}‌}

Version 2.x.x 

In this version, blocks are enclosed with square brackets:

[‌[‌block‌]‌]

You can choose either to replace old syntax with the new syntax, or by setting custom configuration data of the block extension to make it compatible with the old block syntax:

1 => [
    0 => ['{‌{‌', '‌}‌}', '‌/‌'],
    1 => ['=', '"', '"', ' '],
    2 => ['{‌{‌!', '!‌}‌}'],
    3 => ['`{‌{‌', '‌}‌}`']
]

Comments 

  • Store the comments data in lot\comment\article.

Related: Comments

Version 1.x.x 

Name: Taufik Nurrohman
Email: &#101;&#109;&#97;&#105;&#108;&#64;&#100;&#111;&#109;&#97;&#105;&#110;&#46;&#99;&#111;&#109;
URL: http://mecha-cms.com
Status: 1
Content Type: Markdown
Fields: {"user_ip":"114.121.239.123","user_agent":"Mozilla\/5.0 (Windows NT 6.3; rv:43.0) Gecko\/20100101 Firefox\/43.0"}

====

Prior to version 2.x.x, post ID, comment time and parent ID are stored in the file name:

2014-04-01-17-57-36_2014-05-05-09-09-32_0000-00-00-00-00-00.txt

Version 2.x.x 

---
author: Taufik Nurrohman
email: email@domain.com
type: Markdown
link: http://mecha-cms.com
status: 1
user_ip: 114.121.239.123
user_agent: Mozilla/5.0 (Windows NT 6.3; rv:43.0) Gecko/20100101 Firefox/43.0
...

In this version, only the comment time that is stored in the file name. Post ID becomes the parent folder of the comment file, and is using the page slug instead of page ID as the comment reference. Parent ID is stored as a separated file in the related folder:

lot\
 └── comment\
     └── article\
         └── page-slug\
             ├── 2014-05-05-09-09-32\
             │   └── parent.data
             ├── 2014-05-04-06-04-22.page
             └── 2014-05-05-09-09-32.page

To be continued…

0000000000

0 Comments

No comments yet.