Skip to content
This repository was archived by the owner on Nov 14, 2023. It is now read-only.

Commit d4754ea

Browse files
author
Florens Verschelde
committed
A bunch of changes for 3.0 which I was too lazy to split in many commits
1 parent b2802f4 commit d4754ea

File tree

15 files changed

+423
-369
lines changed

15 files changed

+423
-369
lines changed

assets/report.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ button.header-btn:focus {
152152
.results tr.ignore {
153153
background-color: #fAf6f6;
154154
}
155+
.results tr.error {
156+
background-color: #f35f6f;
157+
}
155158
.results tr > :first-child {
156159
width: 42%;
157160
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"autoload": {
1616
"psr-4": {
17-
"Kirby\\StaticBuilder\\": "src/"
17+
"KirbyStaticBuilder\\": "src/"
1818
}
1919
}
2020
}

doc/TODO_3.0

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## 3.0 CHANGELOG
2+
3+
Namespace changes:
4+
5+
- Namespace change from Kirby\StaticBuilder to KirbyStaticBuilder
6+
- Class Kirby\StaticBuilder\Controller renamed to KirbyStaticBuilder\Plugin
7+
- Method Kirby\StaticBuilder\Controller::register now KirbyStaticBuilder\Plugin::register
8+
- Method Kirby\StaticBuilder\Controller::defaultFilter now KirbyStaticBuilder\Plugin::defaultFilter
9+
10+
Configuration changes:
11+
12+
- Default URL strategy is now to use relative URLs ('./')
13+
- Outputdir can now be any *relative* path; some basic checks are in place to avoid overwriting Kirby's standard folders, but please be careful if changing this option!
14+
- Default page extension is now '/index.html' (writing a page at '[outputdir]/page/url/index.html')
15+
16+
Bugfixes:
17+
18+
- Probably fixed, we need to check: https://github.com/fvsch/kirby-staticbuilder/issues/24
19+
-
20+
21+
## TODO:
22+
23+
- https://github.com/fvsch/kirby-staticbuilder/issues/27
24+
- Have a look at: https://github.com/fvsch/kirby-staticbuilder/issues/31
25+
- MAYBE: https://github.com/fvsch/kirby-staticbuilder/issues/11

doc/install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ c::set('staticbuilder', true);
8484
// StaticBuilder requires Kirby’s cache to be disabled
8585
c::set('cache', false);
8686
// Enable routes for the StaticBuilder plugin
87-
Kirby\StaticBuilder\Controller::register();
87+
KirbyStaticBuilder\Plugin::register();
8888
```
8989

9090

doc/options.md

Lines changed: 41 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,105 +9,54 @@ StaticBuilder offers a handful of options so that you can tweak the result, depe
99

1010
```php
1111
c::set([
12-
'staticbuilder' => false,
13-
'staticbuilder.outputdir' => 'static',
14-
'staticbuilder.assets' => ['assets', 'content', 'thumbs'],
15-
'staticbuilder.baseurl' => '/',
16-
'staticbuilder.uglyurls' => false,
17-
'staticbuilder.extension' => '/index.html',
18-
'staticbuilder.filter' => null,
19-
'staticbuilder.withfiles' => false
20-
]);
21-
```
22-
23-
## Common scenarios
24-
25-
### Hosting on a domain or subdomain
26-
27-
With default settings you should be able to put the contents of the `static` folder directly on your website’s root.
28-
29-
- Page files will look like: `my/page.html`
30-
- URLs will look like: `/my/page`
31-
32-
Make sure that your server config allows serving `my/page.html` when requesting the `/my/page` URL.
33-
34-
With Apache, this requires the `Multiviews` options, which you can probably enable in an `.htaccess` file if needed:
12+
// Extension is disabled by default!
13+
'staticbuilder' => false,
3514

36-
```apache
37-
Options +Multiviews
38-
```
39-
40-
### Copying page files
15+
// Pages will we written to: [project_root]/[outputdir]/[page_url][extension]
16+
// Example with default settings: [project_root]/static/parent-page/child-page/index.html
17+
'staticbuilder.outputdir' => 'static',
18+
'staticbuilder.extension' => '/index.html',
4119

42-
There are several options for copying page files and making sure that your links and file references still work.
20+
// Lets you provide an absolute base URL, such as '/' or 'https//domain.tld/'
21+
// If false, we will try to write relative URLs instead
22+
'staticbuilder.baseurl' => false,
4323

44-
1. Copy the thumbs folder. By default the `thumbs` folder will be copied, and if all images you’re using in your pages go through the `thumb()` helper or `$image->thumb()` method, you’re golden.
24+
// Should we add the extension to URLs in the HTML?
25+
'staticbuilder.uglyurls' => false,
4526

46-
2. Copy the content folder and use Kirby tags. By default the `content` folder will be copied as well, so that links to `content/1-section/3-page/myfile.pdf` etc. keep working. If you used Kirby tags to embed images and link to page files, you don’t have anything else to do.
27+
// Files and folders to copy into the static build folder
28+
'staticbuilder.assets' => ['assets', 'content', 'thumbs'],
4729

48-
3. Tell StaticBuilder to copy page files to a folder named after the page: e.g. `section/page/myfile.pdf`.
30+
// Lets you provide a function for including/excluding pages
31+
'staticbuilder.filter' => null,
4932

50-
The last option will work for relative paths in your HTML (`<a href="myfile.pdf">My File</a>` or `<img src="hello.svg" alt="">`) *only if* the page HTML is written to the same folder. So you probably want to use the `extension` and `withfiles` options together:
51-
52-
```php
53-
c::set([
54-
'staticbuilder' => true,
55-
'staticbuilder.extension' => '/index.html',
56-
'staticbuilder.withfiles' => true
33+
// Do not copy files from the page's content folder
34+
'staticbuilder.withfiles' => false
5735
]);
5836
```
5937

60-
### HTML pages outside of a web site
61-
62-
If you need to share the resulting site outside of a web server (on a local network share for documentation, on a thumb drive, distributed as a ZIP file, etc.), you will need fully relative URLs between pages.
63-
64-
This can be achieved with this configuration:
65-
66-
```php
67-
c::set([
68-
'staticbuilder' => true,
69-
'staticbuilder.baseurl' => './',
70-
'staticbuilder.uglyurls' => true
71-
]);
72-
```
73-
74-
In the output, URLs from page A to page B should look like: `./../other-section/page-b.html`.
75-
76-
Note that this plugin only rewrites URLs that are generated by Kirby objects or by the `url()` helper function. If you hardcoded some URLs or paths in your templates, they won’t be rewritten.
77-
78-
7938
## Option details
8039

8140
### `staticbuilder.outputdir`
8241

83-
By default, the static site will be generated in `[yourproject]/static`. You can change this path, providing a relative path (e.g. `../build/static`) or an absolute one (e.g. `/Users/me/Sites/mywebsite/static`).
42+
The default value, `'static'`, means we will ouptut the static build in `[yourproject]/static`.
8443

85-
Two restrictions:
44+
DANGER: the contents of this folder will be *deleted* before each build! If you choose a different folder name or path, make sure it doesn’t match an existing folder like `kirby`, `site`, `thumbs`, etc.
8645

87-
1. PHP and your local web server (Apache/MAMP/WAMP/etc.) must permissions to write to that folder.
88-
2. The output folder MUST be named `static`, even if you change the path. This restriction helps making sure you don’t kill your system or delete existing files.
46+
There are a few restrictions in place:
8947

90-
WARNING: when building the site, the contents of this folder will be deleted first. You should not change the contents of this folder manually, or you will lose your changes on the next build!
48+
1. Absolute paths (`/var/www/static` or `C:\static-site`) are forbidden.
49+
2. PHP and your local web server (Apache/MAMP/WAMP/etc.) must have permissions to write to that folder.
9150

92-
### `staticbuilder.assets`
51+
### `staticbuilder.extension`
9352

94-
A list of static files or folders to copy in the `static` directory.
53+
Extension for pages. Defaults to adding a `/index.html` suffix.
9554

9655
```php
97-
c::set('staticbuilder.assets', [
98-
// Copy the full 'assets' folder
99-
'assets',
100-
// Thumbs too
101-
'thumbs',
102-
// Use key=>value syntax to change the destination
103-
'assets/images/favicon.ico' => 'favicon.ico',
104-
// Getting a file from outside the main project dir
105-
'../server/static-htaccess.conf' => '.htaccess'
106-
]);
56+
c::set('staticbuilder.extension', '/index.html'); // my/page/index.html
57+
c::set('staticbuilder.extension', '.html'); // my/page.html
10758
```
10859

109-
Note: `*` or other wildcards are not supported. You need explicit paths to existing files or folders.
110-
11160
### `staticbuilder.baseurl`
11261

11362
This overrides Kirby’s default `'url'` option.
@@ -124,8 +73,6 @@ c::set('staticbuilder.baseurl', '/something');
12473
c::set('staticbuilder.baseurl', 'http://mysite.com');
12574
```
12675

127-
Finally, there is a magic value for relative URLs:
128-
12976
```php
13077
// Change all URLs to fully relative
13178
c::set('staticbuilder.baseurl', './');
@@ -150,15 +97,25 @@ c::set('staticbuilder.uglyurls', false);
15097
c::set('staticbuilder.uglyurls', true);
15198
```
15299

153-
### `staticbuilder.extension`
100+
### `staticbuilder.assets`
154101

155-
Extension for pages. Defaults to adding a `/index.html` suffix.
102+
A list of static files or folders to copy in the `static` directory.
156103

157104
```php
158-
c::set('staticbuilder.extension', '/index.html'); // my/page/index.html
159-
c::set('staticbuilder.extension', '.html'); // my/page.html
105+
c::set('staticbuilder.assets', [
106+
// Copy the full 'assets' folder
107+
'assets',
108+
// Thumbs too
109+
'thumbs',
110+
// Use key=>value syntax to change the destination
111+
'assets/images/favicon.ico' => 'favicon.ico',
112+
// Getting a file from outside the main project dir
113+
'../server/static-htaccess.conf' => '.htaccess'
114+
]);
160115
```
161116

117+
Note: `*` or other wildcards are not supported. You need explicit paths to existing files or folders.
118+
162119
### `staticbuilder.filter`
163120

164121
With this option you can provide a PHP callback that gets each Page object as its only parameter, and which should return `true` for pages to build and `false` for pages to exclude.
@@ -188,7 +145,7 @@ c::set('staticbuilder.filter', function($page) {
188145
return [false, 'Unpublished articles are excluded from static build'];
189146
}
190147
// And fall back to the default logic for other pages
191-
return Kirby\StaticBuilder\Builder::defaultFilter($page);
148+
return KirbyStaticBuilder\Plugin::defaultFilter($page);
192149
});
193150
```
194151

doc/static.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ c::set('staticbuilder.filter', function($page) {
9999
if ($page->template() == 'article' && $page->isInvisible()) {
100100
return false;
101101
}
102-
return Kirby\StaticBuilder\Builder::defaultFilter($page);
102+
return KirbyStaticBuilder\Plugin::defaultFilter($page);
103103
});
104104
```
105105

File renamed without changes.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "staticbuilder",
33
"description": "Kirby StaticBuilder Plugin",
4-
"version": "2.2.0",
4+
"version": "3.0.0-beta.1",
55
"type": "kirby-plugin",
66
"author": "Florens Verschelde <[email protected]>",
77
"license": "MIT"

0 commit comments

Comments
 (0)