Download the PHP package paulund/content-markdown without Composer
On this page you can find all versions of the php package paulund/content-markdown. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package content-markdown
Content Markdown
Table of Contents
- Content Markdown
- Installation
- Setup
- Add Filesystem Disk
- Setup Database Configuration
- Draft Posts
- Commonmark Configuration
- Content Properties
- Usage
- Index Command
- Get All Content
- Get All Content In Folder
- Get The Latest 10 Content
- Get Content By Slug
- Get Content By Tag
- Populate Content
- Content Cache
- Testing
- Credits
- License
This Laravel pattern with allow you to add a lightweight CMS to your Laravel application. This package will allow you to create markdown files in your Laravel application and then display the content on the front end of your website.
It works by writing in markdown files and then index the slug into the database. This will allow you to query on this slug to get the content of the markdown file.
Installation
Install the package via composer:
Publish the configuration file:
Setup
Add Filesystem Disk
Add the following to your config/filesystems.php
file:
This means you need to create a folder in the storage directory called content
where you can store your markdown files.
You can also add sub categories to the content folder to organise your markdown files.
Setup Database Configuration
Content markdown consists of 3 database tables, content, tags and content_tags. You can create these tables by running the migration:
In the config file you can customise the database table names.
Draft Posts
There are a few ways that you can define a post as a draft.
- In the frontmatter you can use
published: false
- Prefixing the file with
.
will make the file a draft
You can customise the prefix in the config file.
Commonmark Configuration
This package uses commonmark to parse the markdown files. You can customise the configuration of commonmark in the config file.
Content Properties
- title - The title of the content
- slug - The slug of the content
- tags - The tags of the content in array format
- published - A boolean to define if the content is published
- createdAt - The date the content was created
Usage
Index Command
The index command will take the markdown files in the filesystem disk and index the file in the database.
Whenever a new markdown files is created you can run this command to index the file.
This will also run nightly to ensure the index stays up to date.
Get All Content
In order to display all of the content you can use the Content
model to fetch the content.
Get All Content In Folder
You can organise your markdown files into different folders in the filesystem disk. You can query the content by folder.
Get The Latest 10 Content
You can limit the number of content that is returned by using the limit
method.
Get Content By Slug
You can query the content by the slug of the markdown file.
Get Content By Tag
You can query the content by the tag of the markdown file.
Populate Content
Once you have found your content model in the database you can populate it with the content of the markdown file by
using the populate
method.
Content Cache
Whenever you make a request the application will need to lookup the database but the slug of the file, then
lookup the markdown file, then parse the markdown to display it. This can add some latency to the request. To
speed up the request you can cache the content using the CacheResponse
middleware.
This will cache the response for 1 hour using the file store.
If you want to customise the cache settings you can change the store and the ttl.
By default content cache is enabled, but there is a config option to disable it, in your .env file you can add:
Testing
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of content-markdown with dependencies
illuminate/contracts Version ^10.0||^11.0
spatie/commonmark-shiki-highlighter Version ^2.4
symfony/yaml Version ^7.1