Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse the file meta using the Symfony2 YAML Component. #116

Closed
wants to merge 2 commits into from

Conversation

msosvi
Copy link

@msosvi msosvi commented Nov 24, 2013

Allow YAML format in meta info and now custom meta plugin isn't needed.

@Snip1
Copy link
Contributor

Snip1 commented Nov 24, 2013

I'm not familiar with YAML, so pardon the likely ignorance of this question, but: how does this enhance Pico? Can you give an example in the default template?

@msosvi
Copy link
Author

msosvi commented Nov 25, 2013

By using YAML, Pico doesn't need a custom meta plugin. Also with YAML format you can describe a collection that is converted to a PHP array (tags collection, for example).

YAML is used in Jekyll, the static site generator behind Github Pages, for page meta info.

@esamattis
Copy link

This would be awesome. It would make it much easier to migrate from Jekyll to Pico. I got interested in Pico because it is basically like Jekyll but without a build step. Different header format was a bit disappointment because I could not just drop in my Jekyll markdown files.

Also Github supports YAML headers in markdown:
https://github.com/blog/1647-viewing-yaml-metadata-in-your-documents

@esamattis
Copy link

Actually the metadata syntax is now already a subset of YAML. The comment syntax is just incompatible with the de facto style used in Jekyll, Github, Assemble.io, Wintersmith.io and many others. They use three dashes (---) at the start and at the end of the metadata section instead of C style comments. I'd love to see Pico supporting dashes in addition to the current one.

Example:

---
Title: Foo  Bar
---

# Header 1

@williamgrivera
Copy link

This is a great feature! I'm not a developer and I have been hours trying to add custom meta to pages. Right nowwe have to use a hook to add custom meta to pages but with this everything inside /**/ of each page will be cosidered as a meta field. Is that right?

I'm looking forward to build a lot of websites using Pilot. But custom meta is holding me. I do prefer this way.

@msosvi
Copy link
Author

msosvi commented Jul 30, 2014

You are right, with this change Pico doesn't need a custom meta plugin.

@josh7weaver
Copy link

Did this feature get shelved? I'd like to give my vote for integrating it +1

@mistergraphx
Copy link

There is no need to add the YAML Symphony component, just changing the regular expression to this :

/**
     * Parses the file meta from the txt file header
     *
     * @param string $content the raw txt content
     * @return array $headers an array of meta values
     */
    protected function read_file_meta($content){
        global $config;

        $headers = array();

        // Add support for custom headers by hooking into the headers array
        // Is no longer needed but kept for compatibility reasons.
        $this->run_hooks('before_read_file_meta', array(&$headers));

        // Add any meta-headers from your *.md-files.
        if (preg_match_all('/^[-]{3}.(.*?)[-]{3}/ims', $content, $match) && isset($match[1]) && isset($match[1][0])) {
                    $lines = array_filter(explode("\n", $match[1][0]));
                    foreach ($lines as $line) {
                            if (strpos($line, ':') == true) {
                                    list($key, $val) = explode(':', $line);
                                    $headers[trim(strtolower($key))] = trim($val);
                            }
                    }

                    if (isset($headers['date'])) $headers['date_formatted'] = date($config['date_format'], strtotime($headers['date']));

                return $headers;
        }
    }

except if you plan tu use multi-dimentional arrays in meta in the future ... but actualy it's not implemented in Pico.

i already use this and it works ...

@PhrozenByte PhrozenByte mentioned this pull request Aug 28, 2015
@theshka theshka added this to the Version 1.0.0-beta.1 milestone Nov 4, 2015
PhrozenByte added a commit that referenced this pull request Nov 6, 2015
**Note:** This changelog only provides basic information about the enormous
          changes introduced with Pico 1.0.0-beta.1. Please refer to the
          UGPRADE section of the docs for details.

```
* [Security] (9e2604a) Prevent content_dir breakouts using malicious URLs
* [New] Pico is on its way to its first stable release!
* [New] Provide pre-bundled releases
* [New] Heavily expanded documentation (inline code docs, user docs, dev docs)
* [New] New routing system using the QUERY_STRING method; Pico now works
        out-of-the-box with any webserver and without URL rewriting; use
        `%base_url%?sub/page` in markdown files and `{{ "sub/page"|link }}`
        in Twig templates to declare internal links
* [New] Brand new plugin system with dependencies (see `PicoPluginInterface`
        and `AbstractPicoPlugin`); if you're plugin dev, you really should
        take a look at the UPGRADE section of the docs!
* [New] Introducing the `PicoDeprecated` plugin to maintain full backward
        compatibility with Pico 0.9 and Pico 0.8
* [New] Support YAML-style meta header comments (`---`)
* [New] Various new placeholders to use in content files (e.g. `%site_title%`)
* [New] Provide access to all meta headers in content files (`%meta.*%`)
* [New] Provide access to meta headers in `$page` arrays (`$page['meta']`)
* [New] The file extension of content files is now configurable
* [New] Add `Pico::setConfig()` method to predefine config variables
* [New] Supporting per-directory `404.md` files
* [New] #103: Providing access to `sub.md` even when the `sub` directory
        exists, provided that there is no `sub/index.md`
* [New] #249: Support the `.twig` file extension for templates
* [New] #268, 269: Now using Travis CI; performing basic code tests and
        implementing an automatic release process
* [Changed] Complete code refactoring
* [Changed] Source code now follows PSR code styling
* [Changed] Replacing constants (e.g. `ROOT_DIR`) with constructor parameters
* [Changed] Paths (e.g. `content_dir`) are now relative to Pico's root dir
* [Changed] Adding `Pico::run()` method that performs Pico's processing and
            returns the rendered contents
* [Changed] Renaming all plugin events; adding some new events
* [Changed] `Pico_Plugin` is now the fully documented `DummyPlugin`
* [Changed] Meta data must start on the first line of the file now
* [Changed] Dropping the need to register meta headers for the convenience of
            users and pure (!) theme devs; plugin devs are still REQUIRED to
            register their meta headers during `onMetaHeaders`
* [Changed] Exclude inaccessible files from pages list
* [Changed] With alphabetical order, index files (e.g. `sub/index.md`) are
            now always placed before their sub pages (e.g. `sub/foo.md`)
* [Changed] Pico requires PHP >= 5.3.6 (due to `erusev/parsedown-extra`)
* [Changed] Pico now implicitly uses a existing `content` directory without
            the need to configure this in the `config/config.php` explicitly
* [Changed] Composer: Require a v0.7 release of `erusev/parsedown-extra`
* [Changed] #93, #158: Pico doesn't parse all content files anymore; moved to
            `PicoParsePagesContent` plugin, but still impacts performance;
            Note: This means `$page['content']` isn't available anymore, but
            usually the new `$page['raw_content']` is suitable as replacement.
* [Changed] #116: Parse meta headers using the Symfony YAML component
* [Changed] #244: Replace opendir() with scandir()
* [Changed] #246: Move `config.php` to `config/` directory
* [Changed] #253: Assume HTTPS if page is requested through port 443
* [Changed] A vast number of small improvements and changes...
* [Fixed] Sorting by date now uses timestamps and works as expected
* [Fixed] Fixing `$currentPage`, `$nextPage` and `$previousPage`
* [Fixed] #99: Support content filenames with spaces
* [Fixed] #140, #241: Use file paths as page identifiers rather than titles
* [Fixed] #248: Always set a timezone; adding `$config['timezone']` option
* [Fixed] A vast number of small bugs...
* [Removed] Removing the default Twig cache dir
* [Removed] Removing various empty `index.html` files
* [Removed] Moving Pico's excerpt feature to `PicoExcerpt` plugin
```
PhrozenByte added a commit that referenced this pull request Nov 6, 2015
**Note:** This changelog only provides basic information about the enormous
          changes introduced with Pico 1.0.0-beta.1. Please refer to the
          UGPRADE section of the docs for details.

```
* [Security] (9e2604a) Prevent content_dir breakouts using malicious URLs
* [New] Pico is on its way to its first stable release!
* [New] Provide pre-bundled releases
* [New] Heavily expanded documentation (inline code docs, user docs, dev docs)
* [New] New routing system using the QUERY_STRING method; Pico now works
        out-of-the-box with any webserver and without URL rewriting; use
        `%base_url%?sub/page` in markdown files and `{{ "sub/page"|link }}`
        in Twig templates to declare internal links
* [New] Brand new plugin system with dependencies (see `PicoPluginInterface`
        and `AbstractPicoPlugin`); if you're plugin dev, you really should
        take a look at the UPGRADE section of the docs!
* [New] Introducing the `PicoDeprecated` plugin to maintain full backward
        compatibility with Pico 0.9 and Pico 0.8
* [New] Support YAML-style meta header comments (`---`)
* [New] Various new placeholders to use in content files (e.g. `%site_title%`)
* [New] Provide access to all meta headers in content files (`%meta.*%`)
* [New] Provide access to meta headers in `$page` arrays (`$page['meta']`)
* [New] The file extension of content files is now configurable
* [New] Add `Pico::setConfig()` method to predefine config variables
* [New] Supporting per-directory `404.md` files
* [New] #103: Providing access to `sub.md` even when the `sub` directory
        exists, provided that there is no `sub/index.md`
* [New] #249: Support the `.twig` file extension for templates
* [New] #268, 269: Now using Travis CI; performing basic code tests and
        implementing an automatic release process
* [Changed] Complete code refactoring
* [Changed] Source code now follows PSR code styling
* [Changed] Replacing constants (e.g. `ROOT_DIR`) with constructor parameters
* [Changed] Paths (e.g. `content_dir`) are now relative to Pico's root dir
* [Changed] Adding `Pico::run()` method that performs Pico's processing and
            returns the rendered contents
* [Changed] Renaming all plugin events; adding some new events
* [Changed] `Pico_Plugin` is now the fully documented `DummyPlugin`
* [Changed] Meta data must start on the first line of the file now
* [Changed] Dropping the need to register meta headers for the convenience of
            users and pure (!) theme devs; plugin devs are still REQUIRED to
            register their meta headers during `onMetaHeaders`
* [Changed] Exclude inaccessible files from pages list
* [Changed] With alphabetical order, index files (e.g. `sub/index.md`) are
            now always placed before their sub pages (e.g. `sub/foo.md`)
* [Changed] Pico requires PHP >= 5.3.6 (due to `erusev/parsedown-extra`)
* [Changed] Pico now implicitly uses a existing `content` directory without
            the need to configure this in the `config/config.php` explicitly
* [Changed] Composer: Require a v0.7 release of `erusev/parsedown-extra`
* [Changed] #93, #158: Pico doesn't parse all content files anymore; moved to
            `PicoParsePagesContent` plugin, but still impacts performance;
            Note: This means `$page['content']` isn't available anymore, but
            usually the new `$page['raw_content']` is suitable as replacement.
* [Changed] #116: Parse meta headers using the Symfony YAML component
* [Changed] #244: Replace opendir() with scandir()
* [Changed] #246: Move `config.php` to `config/` directory
* [Changed] #253: Assume HTTPS if page is requested through port 443
* [Changed] A vast number of small improvements and changes...
* [Fixed] Sorting by date now uses timestamps and works as expected
* [Fixed] Fixing `$currentPage`, `$nextPage` and `$previousPage`
* [Fixed] #99: Support content filenames with spaces
* [Fixed] #140, #241: Use file paths as page identifiers rather than titles
* [Fixed] #248: Always set a timezone; adding `$config['timezone']` option
* [Fixed] A vast number of small bugs...
* [Removed] Removing the default Twig cache dir
* [Removed] Removing various empty `index.html` files
* [Removed] Moving Pico's excerpt feature to `PicoExcerpt` plugin
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants