This repository was archived by the owner on Jul 27, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathbookstack-new-release-blogpost
116 lines (84 loc) · 3.18 KB
/
bookstack-new-release-blogpost
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
#!/usr/bin/env php
<?php
// Script to create a new blogpost, with a cover image created at the right size
// and attribution ready set.
$siteDir = '/home/dan/web/bs-site';
$key = getenv('UNSPLASH_ACCESS_KEY');
if (!$key) {
error("Unsplash access key needs to be set on [UNSPLASH_ACCESS_KEY] environment variable to run this script");
}
$unsplashId = read("Enter the unsplash image ID:");
$imageDesc = read("Enter a short one/two word description of the image:");
$version = read("Enter the BookStack version (eg. v21.03 or v21.12.3):");
// Fetch and write out image
$image = unsplashGet($unsplashId, $key);
$imageContent = getImageContent($image, 2100, 800, 60);
$imageOutName = str_replace(' ', '-', strtolower($imageDesc)) . "-" . $image->user->username . '.jpg';
$imageOutPath = implode(DIRECTORY_SEPARATOR, [$siteDir, "static/images/blog-cover-images", $imageOutName]);
file_put_contents($imageOutPath, $imageContent);
// Write out blogpost
$hyphenVersion = str_replace('.', '-', trim($version));
$postMdName = "bookstack-release-{$hyphenVersion}.md";
$postMdOutPath = implode(DIRECTORY_SEPARATOR, [$siteDir, "content/blog", $postMdName]);
$postMdContent = getPostMarkdown();
file_put_contents($postMdOutPath, $postMdContent);
output("Done, Post created at {$postMdOutPath}");
function unsplashGet(string $id, string $unsplashKey) {
$json = file_get_contents("https://api.unsplash.com/photos/{$id}?client_id={$unsplashKey}");
return json_decode($json);
}
function getImageContent($unsplashImage, int $width, int $height, int $quality) {
$url = $unsplashImage->urls->raw;
$url .= "&fm=jpg&w={$width}&h={$height}&fit=crop&q={$quality}&crop=focalpoint,center";
return file_get_contents($url);
}
function getPostMarkdown() {
global $image, $imageContent, $version, $hyphenVersion, $imageOutName;
$date = str_replace('+00:00', 'Z', date('c'));
$content = <<<POSTCONTENT
+++
categories = ["Releases"]
tags = ["Releases"]
title = "BookStack Release $version"
date = $date
author = "Dan Brown"
image = "/images/blog-cover-images/$imageOutName"
slug = "bookstack-release-$hyphenVersion"
draft = false
+++
Intro
* [Update instructions](https://www.bookstackapp.com/docs/admin/updates)
* [GitHub release page](https://github.com/BookStackApp/BookStack/releases/tag/$version)
**Upgrade Notices**
TODO
- **Title** - Detail
TODO - Video
### New Feature A
TODO
### Translations
TODO
- Username - *Language*
### Next Steps
TODO
### Full List of Changes
**Released in $version**
TODO
----
<span style="font-size: 0.8em;opacity:0.9;">Header Image Credits: <span>Photo by <a href="https://unsplash.com/@{$image->user->username}?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">{$image->user->name}</a> on <a href="https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a></span></span>
POSTCONTENT;
return $content;
}
function error($text) {
echo $text . "\n";
exit(1);
}
function output($text) {
echo $text . "\n";
}
function read($question): string {
$response = readline($question);
if (!$response) {
error("Failed to respond to question (" . $question . ")");
}
return $response;
}