Download the PHP package cspray/blogisthenics without Composer
On this page you can find all versions of the php package cspray/blogisthenics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cspray/blogisthenics
More information about cspray/blogisthenics
Files in cspray/blogisthenics
Package blogisthenics
Short Description Put your blog generation on a diet with Blogisthenics!
License
Informations about the package blogisthenics
Blogisthenics
Are you looking for a static site generator with the following features:
- A SPA using the latest JavaScript Web Components?
- The newest CSS frameworks baked right in?
- Access to the fanciest, most modern templating engine?
- Integration with your favorite framework?
Then this project isn't for you because Blogisthenics doesn't offer any of those things! And never will! What do we give you instead?
- A way to create a boring ol' multi-page application using HTML, Markdown, and a minimal amount of CSS; where clicking on a link makes the whole page refresh. So old school!
- Powerful, no-frills templating engine that's been in use for over 20 years. PHP itself!
- Customize your dynamic content with Front Matter... not written in YAML!
- Absolutely no JavaScript or related tooling out-of-the-box. I prefer to have just 1 shitty language in my site generators, thank-you-very-much!
- Cohesive, type-safe, testable mechanisms for programmatically controlling the content of your site!
Usage Guide
Oh, shit. You're still here? In all honesty, you probably shouldn't use this software! There's just an ass-load of site generators out there and nearly all of them are going to be more supported than whatever this ball of crap turns into. The stuff I write below is mostly for my own benefit so when I come back here in 6 months I can figure out what the hell is going on.
Directory Structure
Blogisthenics follows a principle that there are reasonable defaults for your site configuration, but you can override any of the defaults to customize your installation. Your directory structure should resemble the following:
Content Overview
Content for your site gets lumped into three categories:
- Static Assets
- Layouts
- Pages
Static Assets
Static assets are any content in your site that should not be dynamically rendered, whatever is in the file gets copied over exactly, with the same path, when the site is built. Specifically the following functionalities are not supported by static assets.
- Front Matter Parsing
- Template processing, i.e. no variables
- Multiple extension formatting support
Pages
Pages are .html
, .md
, and .php
files that act as specific content for a path that will be added to your site. Pages are expected to be only partial HTML documents and must define a layout. If a layout is not explicitly defined in the Front Matter of a page we use the default layout from the site configuration.
Layouts
Layouts are .md
and .php
files that act as the outer chrome for pages. Layouts can be inserted into other layouts. The below example demonstrates a minimal layout, typically named something like main.html.php
or default.html.php
.
Note the call to $this->yield()
, when in a layout this is required to output the content being injected. If you attempt to call $this->yield()
from a non-layout piece of Content an exception will be thrown. Check out the "Templating" section below for more details on using Pages and Layouts.
Templating
Blogisthenics uses PHP itself as the templating engine. On top of that we add some functionality to allow the following features:
- Nesting an arbitrary level of layouts
- Auto-escaping all values, including ability to escape contextually.
- Providing access to the FrontMatter of the layout and page
- Provide read-only access to the loaded data
- Allow the creation of helper methods for outputting common pieces of content
The majority of the functionality described in this section refers to the Cspray\Blogisthenics\Context
object. This object is defined as $this
in your templates. The simplest templates might look something like the following.:
When built, your site would include an index.html
file that resembles the following:
Template Helpers
Sometimes what you want to do might be too advanced for a static front matter or would be easier to share across many pages and layouts if it was encapsulated in a method you could invoke inside a template. Using the TemplateHelperProvider
you can add template helper methods easily and then get access to them in your templates.
To utilize template helpers you'll have to implement some PHP code. In addition to whatever your helper does you'll have to make sure it gets integrated with Blogisthenics. Fortunately, that's easy to do thanks to Annotated Container. This code should live somewhere in the src
directory of your Blogisthenics site.
Inside your template you can now invoke $this->myHelper()
!
Auto-Escaping
Since Content can be generated at runtime with Front Matter that could include data from external sources Blogisthenics takes the stance that all of your data should be escaped properly. Utilizing the laminas/escaper project we automatically escape all values originating from the Context object. Meaning, all of your front matter, method helpers, and loaded JSON data get automatically HTML escaped at the time of output. If you don't want the value from a helper method to be escaped automatically wrap it in the value object Cspray\Blogisthenics\SafeToNotEncode
.
Future updates will add a template API for contextually aware escaping. In other words, you'll be able to implicitly and explicitly escape a piece of data with awareness of whether it is CSS data, or JS data, or HTML data.
Template Formatting
As already mentioned, we support the ability to create pages out of Markdown documents. Specifically, Blogisthenics uses GitHub Flavored Markdown provided by the league/commonmark package. After all, writing a blog in just HTML would start to get pretty old... blog articles are pretty good candidates for Markdown. Instead of baking Markdown support into Blogisthenics somewhere we expose an interface called Cspray\Blogisthenics\Formatter
that provides an opportunity for a rendered template to have some additional formatting applied. The Cspray\Blogisthenics\GitHubFlavoredMarkdownFormatter
is the implementation taking care of Markdown. You can implement your own Formatter
instance if you find Blogisthenics minimalist approach too spartan for you. We'll be taking advantage of Annotated Container to easily integrate your Formatters into Blogisthenics. This code should live somewhere in the src
directory of your Blogisthenics site.
Now any template you create that ends in my-type
or my-type.php
will be passed to MyCustomFormatter
before the contents are written to disk.
Dynamic Content
Sometimes it isn't possible to create all the necessary content ahead of time in static files. You may need to have access to the content of the site or some other information that requires you to provide the Content at runtime. You can take care of this in Blogisthenics by implementing the Cspray\Blogisthenics\DynamicContentProvider
interface. We'll be using Annotated Container to easily integrate your implementations. This code should live somewhere in the src
directory of your Blogisthenics site.
Programmatic Data
Sometimes your blog or site might need to include some programmatically loaded data. Inside Blogisthenics this data gets
stored in the Cspray\Blogisthenics\KeyValueStore
. You can depend on this service in your own #[Service]
and a mutable
implementation will be injected. In Template contexts you can get access to an immutable store through the Context::kv()
method, $this->kv()
in your templates. You can load data into the KeyValueStore
in 1 of 2 methods; statically or
through programmatic calls.
Loading Static Files
In your data directory, by default /data
in your site's root, all JSON files will be loaded and stored in the
KeyValueStore
. All data is namespaced with the name of the file and keys in the JSON object are accessible through
dot-notation. For example, If you have the following JSON file stored in /data/foo.json
you can make the below method
calls in your template.
Loading Dynamic Data
Maybe you don't know ahead of time what data needs to be loaded. In those situations you should implement a
Cspray\Blogisthenics\DataProvider
instance. We'll be taking advantage of Annotated Container to easily integrate this
instance. Somewhere in your /src
directory you should implement the following:
Just like statically loaded files you can access whatever data you load into the store through dot-notation. Unlike statically loaded files nothing is autonamespaced. If your data needs require a namespace you should make sure you do that in the keys you use to set data.
Why?!
Holy shit, cspray! Have you never heard of Jekyll, or Hugo, or any of the 134 bajillion generators listed on the JAMStack site?
Well, clearly I know about them. I included links to their sites! There's 4 primary reasons I did this.
- I'm a masochist.
-
When I look at site generators out there I see a lot of libraries with, from my perspective, the following drawbacks:
- Aren't written in PHP
- Create sites using SPA architectures
- Require me to use Laravel or Symfony
I want to use PHP to build my site, and without requiring Laravel or Symfony to do so. I didn't find anything targeted towards the framework-less audience, so I built it myself.
- Opportunity to dogfood Annotated Container.
- Creating things to learn how they work or how I might accomplish it is how I learn things. It is kinda my jam.
All versions of blogisthenics with dependencies
laminas/laminas-escaper Version ^2.10.0
league/commonmark Version ^2.3
minicli/minicli Version ^3.2
minicli/command-help Version ^0.1.0
voku/stringy Version ^6.5
adbario/php-dot-notation Version ^3.1
cspray/annotated-container Version ^1.2
rdlowrey/auryn Version ^1.4
monolog/monolog Version ^3.1