Katana-the PHP static site blog builder that supports Markdown syntax already has several static site generators, such as Hexo and Jekyll. Today, we found a static blog builder using PHP syntax, supports the Markdown syntax and uses the Laravel Blade template engine.
Katana features:
- Supports Markdown syntax
- Quick installation
- Built-in Pretty URLs
- Simple article pagination
- Github Pages Supported
I. Installation
It is very easy to install Katana. you only need to run the composer create-project command:
composer create-project themsaid/katana your-site-name
Now that you have installed Katana in the your-site-name Directory, run the following command to generate the site:
cd your-site-namephp katana build
A public directory will be generated in the folder, which is the generated static file.
Specify baseURL for bulid
When generating a static file, you can use base_url to specify the baseUrl:
php katana build --base_url=/awesome-site
In this case, the url:/awesome-site/about will be generated when you use the @ url () command of Blade to generate a link.
II. directory structure
After running the build command, the following file structure is generated:
- Content: This is where Katana is looking for content on your website.
- _ Cache: This is where Blade saves the compiled view file.
- Public: Katana will save the generated static file here
- Config. php: Website configuration items
2.1 about the "content" directory structure
This folder stores your Blade views, static files (JS, CSS, images, etc ),_ BlogFolder and_ IncludeFolder.
The _ content folder stores your Blade layout and basic views. Katana does not generate accessible pages for these files.
_ The blog folder is the place where the blog content is stored.
2.2 about config. php
This file contains some predefined meanings required by Katana to generate static files. each configuration item has a detailed description of what they are used.
You can also define any variable in this file, and then call this variable in any view of the website.
III. Blade Template
If you are not familiar with the Blade template, the following section describes the Blade template from the Laravel website:
Blade is a simple but powerful template engine provided by Laravel. Unlike other mainstream PHP template engines, Blade does not limit you to use pure PHP code in the view.
We recommend that you read the Blade documentation here.
3.1 Use Markdown syntax in Blade
Katana adds a @ markdown command for Blade. you can use it like this:
Regular HTML heading@markdown This is some **Markdown** content.@endmarkdown
3.2 generate URLs
Katana uses the @ url () command of Blade to generate URLs for pages and static files. These URLs are based on the base_url parameter specified during build:
@('/') // Outputs '/'@('about') // Outputs '/about'@('assets/style.js') // Outputs '/assets/style.js'
4. blog builder
It is very easy to use Katana to generate a blog./Content/_ blogThe folder always creates a file and follows the format below:
2016-03-03-my-post-slug.blade.php
The date before the file name is used to sort the files in the file system and also to generate the blog URL. the above file will generate the following URL:
blog.com/my-post-slug-20160303
4.1 variables in blog posts
The blog View should look like the following:
@section('post::title', 'Stop Trying To Be Somebody')@section('post::date', 'February 28, 2016')@section('post_body') @yield('post::title') @yield('post::date') Post content here.@stop
Sections starting with post: are added to the global variable $ blogPosts. this variable can be used in all views and contains an array of article objects.
You can use this variable to output all blog posts cyclically:
@foreach($blogPosts as $blogPost)
path }}"> {{ $blogPost->title }} at {{ $blogPost->date }} @endforeach
The path attribute is automatically added by Katana and stores the relative URL of the document.
4.2 blog article pagination
To display blog posts on Katana pages, you must firstConfig. phpPostsPerPage and postsListView configuration items. When you look at the configuration file, you will know what each configuration item is.
In the pagination view, the $ paginatedBlogPosts variable contains all the articles on this page, while the $ nextPage and $ previousPage variables are links of the next page and the previous page respectively.
5. Github Pages
You can deploy the site on Github Pages. The idea isPublicDirectory is the main branch of your Github Pages Library or the gh-pages branch of other libraries.
Step 1: Add Katana to other branches except the master/gh-pages branch.
Here we call this branchGh-pages-sourceInstall Kanata to this branch and add the content according to the normal steps.
Setp 2: generate a site
After the content is ready, you can run build to generate the site:
php katana build
If you are not using your username project, you need to define base_url, for example, my Github username is9 IPHPBut I didn't release Katana to the project 9IPHP.github.com, but set up a Katana Project, and the site needs to be generated as follows:
php katana build --base_url=/Katana
Step 3: Push the file to the branch created in Step 1
Remove. GitignoreFilePublicThis line, otherwise the directory cannot be submitted, and then run the following command:
git add --allgit commit -m 'publishing website'git push origin gh-pages-source
Step 4: add the public directory to the master/gh-pages branch
git subtree push --prefix public origin master
Or:
git subtree push --prefix public origin gh-pages
VI. Summary
After the creation is complete, you can visit the website in your Github Pages. you can view the sample site I created.
Github address of the project