This repository has been archived by the owner on May 24, 2022. It is now read-only.
/
sitebuilder.php
131 lines (101 loc) · 3.79 KB
/
sitebuilder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
$sc = require_once __DIR__.'/src/bootstrap.php';
// Render the site with the given config file
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
$console = new Application('SiteBuilder', '3.5.4');
$console
->register('rebuild')
->setDescription('Renders all content, writes to output folder')
->setHelp(<<<'EOH'
This command renders your content files and saves them in the output folder.
Run it like this:
%command.full_name%
EOH
)
->setDefinition(array())
->addOption('force', false, InputOption::VALUE_NONE, 'Overwrite all files, even if unchanged')
->addOption('delete', false, InputOption::VALUE_NONE, 'Delete files from output if they aren\'t in content')
->setCode(function (InputInterface $input, OutputInterface $output) use ($sc) {
$filesystem = $sc->get('sitebuilder_filesystem');
$output->writeln('<info>Copying and transforming content</info>');
$filesystem->mirror(
$sc->getParameter('content_dir'),
$sc->getParameter('output_dir'),
null,
array(
'override' => $input->getOption('force'),
'delete' => $input->getOption('delete'),
)
);
})
;
$console
->register('init')
->setDescription('Create necessary folders')
->setHelp(<<<'EOH'
This command creates the content, output, and template folders that
SiteBuilder expects.
Run it like this:
%command.full_name%
EOH
)
->setDefinition(array())
->setCode(function (InputInterface $input, OutputInterface $output) use ($sc) {
foreach (array('content', 'output', 'templates', 'cache') as $dir) {
if (!is_dir($dir)) {
mkdir($dir);
}
}
if (!is_file('config.ini')) {
$template =<<<'EOF'
[parameters]
; Where to look for templates, and the name of the default template
template_path = templates
default_template = template.twig
; Where to look for content files
content_dir = content
; Where to put the generated site
output_dir = output
; Where the sass binary lives. Leave it blank if you don't have it
sass_path =
; Cache directory (can speed things up, but also make it hard to debug stuff)
; Leave it 'false' unless you're doing something clever
cache = false
EOF;
file_put_contents('config.ini', $template);
}
if (!is_file('templates/template.twig')) {
$template =<<<'EOF'
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>{{ title }}</title>
</head>
<body>
{{ content | raw }}
</body>
</html>
EOF;
file_put_contents('templates/template.twig', $template);
}
if (!is_file('content/example.md')) {
$example =<<<'EOF'
---
# This is a YAML block and sets variables you can call in your template, for example:
title: Markdown example
# You can also override the default template by setting a template variable, e.g.:
template: template.twig
---
#Hello World
Lorem ipsum dolor sit *amet*, consectetur adipisicing elit, [sed do eiusmod tempor](http://www.example.com/) incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco **laboris nisi** ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
EOF;
file_put_contents('content/example.md', $example);
}
})
;
$console->run();