-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyaml-management.php
68 lines (47 loc) · 1.82 KB
/
yaml-management.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
<?php
require_once 'loader.php';
$directories = glob('web/*', GLOB_ONLYDIR);
$slugs_and_titles = ArtlungLab\Nav::getMetadata();
foreach ($directories as $directory) {
$just_slug = str_replace('web/', '', $directory);
$yaml_file = "$directory/$just_slug.yaml";
if (!file_exists($yaml_file)) {
touch($yaml_file);
}
$yaml = Spyc::YAMLLoad($yaml_file);
$original_yaml = $yaml;
if (!isset($yaml['slug']) || $yaml['slug'] != $just_slug) {
$yaml['slug'] = $just_slug;
}
if (!isset($yaml['canonical_url']) || $yaml['canonical_url'] != "https://lab.artlung.com/$just_slug/") {
$yaml['canonical_url'] = "https://lab.artlung.com/$just_slug/";
}
if (!isset($yaml['year'])) {
$yaml['year'] = (int) date('Y');
}
// if title not set, set it to the first h1 in the file slug/slug.php
if (!isset($yaml['title'])) {
$slug_file = "$directory/$just_slug.php";
$slug_content = file_get_contents($slug_file);
$matches = [];
preg_match('/<h1>(.*?)<\/h1>/', $slug_content, $matches);
if (isset($matches[1])) {
$yaml['title'] = $matches[1];
}
}
if (!isset($yaml['tags']) || !is_array($yaml['tags']) || count($yaml['tags']) == 0) {
$yaml['tags'] = [];
print "No tags for $just_slug, be sure to run php tag-adder.php\n";
}
if (!isset($yaml['og-image-date'])) {
print "No og-image-date for $just_slug, be sure to run php og-images.php\n";
}
// is the yaml different?
if ($yaml != $original_yaml) {
$yaml_string = Spyc::YAMLDump($yaml);
file_put_contents($yaml_file, $yaml_string);
print "Yaml file changed for $just_slug\n";
print "Run php tag-adder.php and php og-images.php\n";
print "Also run php composer updatenav\n";
}
}