Skip to content

Commit 1078ff0

Browse files
authored
Create README.md
1 parent dd7059f commit 1078ff0

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Press
2+
An elegant markdown-powered Blog for the Laravel Framework.
3+
4+
This package provides all of the bare bones to build a blog in Laravel. The posts come from parsed markdown files and are stored in 1 of 3 location. The location of the files is driven by 1 of the 3 built-in drivers for file, database and gist.
5+
6+
## Basics
7+
8+
### Press File Format
9+
10+
Here is a sample file. All of the fields are the top are customizable and extendable by publishing the service provider and adding your own field definitions.
11+
12+
~~~markdown
13+
---
14+
title: A very important title will go here
15+
keywords: github, gists, coder's tape
16+
description: Here we will describe the blog post in sentence form.
17+
date: May 14 2020
18+
tags: News, GitHub
19+
20+
---
21+
22+
### Markdown can be used here and even <strong>HTML</strong>
23+
24+
Here is the body of the post
25+
~~~
26+
27+
## Drivers
28+
29+
### File Driver
30+
31+
The file driver will simply look for `.md` files inside a predetermined directory. This is useful for creating blog posts and keeping them inside of your source control.
32+
33+
### Database Driver
34+
35+
As the name suggest, this will store all of your raw markdown files (before being processed) in the database. This is specially helpful for allowing for an admin panel where a user can edit the blog posts inside of the browser. We have provided the controller for basic Admin panel but no views have been provided.
36+
37+
### Gist Driver
38+
39+
The GitHub Gist driver is great for those looking to bring in posts from different sources. It uses a single file as the main source and that file should contain all of the Gists that you would like included inside of the blogs. Any public gist can be used from any source.
40+
41+
## Customizations
42+
43+
### Custom Fields
44+
45+
Any of the fields in the header of the markdown document can be customized for your project.
46+
47+
1. Publish the PressServiceProvider with `php artisan vendor:publish --tag press-provider`
48+
2. Create a class using this stub
49+
50+
~~~php
51+
<?php
52+
53+
namespace App\Fields;
54+
55+
use coderstape\Press\Field\FieldContract;
56+
57+
class Published extends FieldContract
58+
{
59+
/**
60+
* Process the field and make any needed modifications.
61+
*
62+
* @param $fieldType
63+
* @param $fieldValue
64+
* @param $fields
65+
*
66+
* @return array
67+
*/
68+
public static function process($fieldType, $fieldValue, $fields)
69+
{
70+
return [
71+
'active' => ($fieldValue == 'yes') ? 1 : 0,
72+
];
73+
}
74+
}
75+
~~~
76+
77+
> Recommended to add a directory under `app` named `Fields` to store all of your custom fields.
78+
79+
3. Register your new custom field in the service provider
80+
81+
~~~php
82+
/**
83+
* Bootstrap any additional custom field parsers.
84+
*
85+
* @return array
86+
*/
87+
public function fields()
88+
{
89+
return [
90+
\App\Fields\Published::class,
91+
];
92+
}
93+
~~~
94+
95+
4. To use it simply add to the header section of the markdown file and it will be saved in the extras column of your parsed press file.
96+
97+
5. Using it in your custom views is easy using the `->extra()` method. For this particular example, you may call `$post->extra('published')` as you are iterating through posts.
98+
99+
### Customizing Editors
100+
101+
> This required the database driver
102+
103+
To edit who can edit the blog posts when using the database driver, you can add the following to the PressServiceProvider
104+
105+
~~~php
106+
/**
107+
* Bootstrap any package services.
108+
*
109+
* @return void
110+
*/
111+
public function boot()
112+
{
113+
Press::fields($this->fields());
114+
115+
Press::editors([
116+
117+
118+
]);
119+
}
120+
~~~
121+
122+
Listing out all of the emails of authenticated users that have rights to edit this. In your views or controllers, there's a handy method to check if a user is authorized to perform editing functions.
123+
124+
Using the Press facade you can call `Press::isEditor()` to get a boolean value.
125+
126+
+ In Blade views
127+
128+
~~~php
129+
@if(Press::isEditor())
130+
<a href="{{ Press::path() . '/admin' }}">Admin</a>
131+
@endif
132+
~~~
133+
134+
+ In controllers
135+
136+
~~~php
137+
use coderstape\Press\Facades\Press;
138+
139+
public function show($post)
140+
{
141+
if ( !Press::isEditor()) {
142+
return redirect()->to('other/address/here');
143+
}
144+
145+
// Controller stuff here...
146+
}
147+
~~~

0 commit comments

Comments
 (0)