-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.php
76 lines (56 loc) · 2.15 KB
/
build.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
#!/usr/bin/env php
<?php
declare(strict_types=1);
const ROOT_DIR = __DIR__;
\chdir(ROOT_DIR . '/source');
\exec('git clone https://github.com/php-censor/php-censor.git "docs-raw"');
\mkdir('docs/plugins', 0755, true);
\mkdir('docs/sources', 0755, true);
\mkdir('docs/workers', 0755, true);
\exec('cp --recursive --no-target-directory "docs-raw/docs/images" "assets/img/docs"');
\exec('cp --recursive --no-target-directory "docs-raw/docs/screenshots" "assets/img/docs/screenshots"');
$config = require 'navigation.php';
$result = [];
function parse(array $config, &$result): void {
foreach ($config as $name => $value) {
if (\is_string($value)) {
if ($value) {
$result[$value] = $name;
}
continue;
}
if (!empty($value['children'])) {
if (isset($value['url']) && $value['url']) {
$result[$value['url']] = $name;
}
\parse($value['children'], $result);
continue;
}
\parse($value, $result);
}
}
\parse($config, $result);
foreach ($result as $path => $title) {
$newPath = 'docs-raw/docs/en/' . \substr($path, \strlen('docs/'));
/* if ('docs/upgrade_from_1_to_2' === $path) {
$newPath = 'docs-raw/docs/UPGRADE_2.0';
}
if ('docs/changelog_2_1' === $path) {
$newPath = 'docs-raw/CHANGELOG';
}*/
$content = \file_get_contents($newPath . '.md');
$content = \str_replace(['../screenshots/', '../images/'], ['/assets/img/docs/screenshots/', '/assets/img/docs/'], $content);
$content = \preg_replace(['#docs/en/(plugins|sources|workers)/([-_\w\d]+?)\.md#'], ['$1/$2'], $content);
$content = \preg_replace(['#docs/en/([-_\w\d]+?)\.md#'], ['$1'], $content);
$content = \preg_replace(['#(plugins|sources|workers)/([-_\w\d]+?)\.md#'], ['$1/$2'], $content);
$content = \preg_replace(['#\(([-_\w\d]+?)\.md\)#'], ['($1)'], $content);
$prefix = "---
title: {$title}
description: {$title}
extends: _layouts.documentation
section: content
---
";
\file_put_contents($path . '.md', \sprintf('%s%s', $prefix, $content));
}
\exec('rm --force --recursive --verbose "docs-raw"');