├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json └── src ├── Blog.php ├── Component.php ├── Twig ├── ExpressionParser.php ├── Markdown.php ├── Object.php ├── Page.php ├── Parser.php └── Theme.php └── templates ├── blog-archives.html.twig ├── blog-authors.html.twig ├── blog-listings.html.twig ├── blog-page.html.twig ├── blog-post.html.twig └── blog-tags.html.twig /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | 4 | The format is based on [Keep a Changelog](http://keepachangelog.com/) 5 | and this project adheres to [Semantic Versioning](http://semver.org/). 6 | 7 | ## [Unreleased] 8 | 9 | ## [1.4] - 2017-01-08 10 | ### Added 11 | - ParsedownExtra as default markdown provider 12 | - Custom callable markdown implementations 13 | 14 | ## [1.3] - 2017-01-04 15 | ### Added 16 | - Microtimes to Twig templates debug data 17 | - Static Theme dumper method 18 | 19 | ## [1.2] - 2016-11-29 20 | ### Added 21 | - Twig dir function for relative paths 22 | 23 | ### Changed 24 | - Only save html pages in database 25 | 26 | ### Fixed 27 | - Empty category undefined offset 28 | 29 | ## [1.1] - 2016-10-25 30 | ### Added 31 | - Optionally specify Twig array keys via '**:**' colon, similar to hashes 32 | - Improved Global Vars Dump 33 | 34 | ### Fixed 35 | - Relative asset paths for Twig v1.27.0 36 | 37 | ## [1.0] - 2016-10-13 38 | - Initial Release 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Kyle Gadd 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # use BootPress\Blog\Component as Blog; 2 | 3 | [![Packagist][badge-version]][link-packagist] 4 | [![License MIT][badge-license]](LICENSE.md) 5 | [![HHVM Tested][badge-hhvm]][link-travis] 6 | [![PHP 7 Supported][badge-php]][link-travis] 7 | [![Build Status][badge-travis]][link-travis] 8 | [![Code Climate][badge-code-climate]][link-code-climate] 9 | [![Test Coverage][badge-coverage]][link-coverage] 10 | 11 | A flat file Blog and CMS that doesn't skimp on features, and can be utilized in any website. 12 | 13 | ## Installation 14 | 15 | Add the following to your ``composer.json`` file. 16 | 17 | ``` bash 18 | { 19 | "require": { 20 | "bootpress/blog": "^1.0" 21 | } 22 | } 23 | ``` 24 | 25 | Create an ``.htaccess`` file in your website's public root folder to redirect everything that doesn't exist to an ``index.php`` file. 26 | 27 | ```htaccess 28 | # Prevent directory browsing 29 | Options All -Indexes 30 | 31 | # Turn on URL re-writing (remove 'example.com/' if not on localhost) 32 | RewriteEngine On 33 | RewriteBase /example.com/ 34 | 35 | # If the file exists, then that's all folks 36 | RewriteCond %{REQUEST_FILENAME} -f 37 | RewriteRule .+ - [L] 38 | 39 | # For everything else, there's BootPress 40 | RewriteRule ^(.*)$ index.php [L] 41 | ``` 42 | 43 | Your ``index.php`` file should then look something like this: 44 | 45 | ```php 46 | '../page', // a private (root) directory 58 | 'base' => 'http://localhost/example.com', 59 | 'suffix' => '.html', 60 | )); 61 | $html = ''; 62 | 63 | // Deliver sitemap and assets first 64 | if ($asset = Asset::cached('assets')) { 65 | $page->send($asset); 66 | } elseif ($xml = Sitemap::page()) { 67 | $page->send($xml); 68 | } 69 | 70 | // Implement a blog 71 | $blog = new Blog(); 72 | if (false !== $file = $blog->page()) { 73 | if (is_array($file)) { // An 'index.html.twig' file 74 | $html = $blog->theme->renderTwig($file); 75 | } else { // A 'txt', 'json', 'xml', 'rdf', 'rss', or 'atom' page 76 | $page->send(Asset::dispatch($page->url['format'], $file)); 77 | } 78 | } else { 79 | $page->send(404); 80 | } 81 | 82 | // Create the layout 83 | $html = $page->display($blog->theme->layout($html)); 84 | 85 | // Send to user 86 | $page->send(Asset::dispatch('html', $html)); 87 | ``` 88 | 89 | ## Setup Blog 90 | 91 | Create a ``../page/blog/config.yml`` file with the following information: 92 | 93 | ```yaml 94 | blog: 95 | name: Example # The name of your website 96 | image: logo.png # The main image relative to this directory 97 | listings: blog # The url base for all your listing pages - authors, archives, tags, etc. 98 | breadcrumb: Blog # How to reference the listings in your breadcrumbs array 99 | theme: default # The main theme for your site 100 | ``` 101 | 102 | You can access any of these in your Twig templates eg. ``{{ blog.name }}``, including the ``{{ blog.page }}`` you are on. Eventually this file will be full of authors, categories, and tags that you can easily manage as well. You can create a [Bootstrap list group](http://getbootstrap.com/components/#list-group) of categories by: 103 | 104 | ```twig 105 | 114 | ``` 115 | 116 | Other ``{{ blog.query(...) }}``'s include '**tags**', '**authors**', '**archives**', '**recent**', '**featured**', '**similar**', '**posts**', and **[...]** listings of every sort, otherwise known as "The Loop". 117 | 118 | ## Create Content 119 | 120 | A BootPress Blog is a flat-file CMS, which means you don't need any fancy admin interface to manage all of the content that is scattered througout a database. You simply create files. All of your blog's posts and pages will reside in the ``../page/blog/content/`` directory, and if you look at a URL, you will be able to follow the folders straight to your ``index.html.twig`` file. For example: 121 | 122 | | URL | File | 123 | | ------------------------------------- | ------------------------------------------------------------ | 124 | | / | blog/content/index.html.twig | 125 | | /feed.rss | blog/content/feed.rss.twig | 126 | | /about-me.html | blog/content/about-me/index.html.twig | 127 | | /category/post.html | blog/content/category/post/index.html.twig | 128 | | /category/subcategory/long-title.html | blog/content/category/subcategory/long-title/index.html.twig | 129 | 130 | Why not have the '**/about-me.html**' URL file at '**content/about-me.html.twig**' instead of '**content/about-me/index.html.twig**' instead, right? This is so you can have all of the assets that you want to use, right there where you want to use them. Linking to them is even easier. Place an '**image.jpg**' in the '**content/about-me/**' folder, and link to ``{{ 'image.jpg'|asset }}`` in the '**index.html.twig**' file. Would you like to resize that? Try an ``{{ 'image.jpg?w=300'|asset }}``. To see all the options, check out the [Quick Reference "Glide"](http://glide.thephpleague.com/1.0/api/quick-reference/). 131 | 132 | Non-HTML files are accessed according to the '**/feed.rss**' URL example above. 133 | 134 | ## Twig Templates 135 | 136 | Every ``index.html.twig`` file is a Twig template that receives the [BootPress Page Component](https://packagist.org/packages/bootpress/page), so that you can interact with your HTML Page. The methods available to you are: 137 | 138 | - ``{{ page.set() }}`` - Set HTML Page properties. Things like the title, keywords (tags), author, etc. 139 | - ``{{ page.url() }} `` - Either create a url, or manipulate it's query string and fragment. 140 | - ``{{ page.get() }} `` - Access $_GET parameters. 141 | - ``{{ page.post() }}`` - Access $_POST parameters. 142 | - ``{{ page.tag() }} `` - Generate an HTML tag programatically. 143 | - ``{{ page.meta() }} `` - Insert ```` tag(s) into the ```` section of your page. 144 | - ``{{ page.link() }} `` - Include js, css, ico, etc links in your page. 145 | - ``{{ page.style() }} `` - Add CSS ``