From: Dan Brown Date: Sat, 6 Feb 2021 15:45:14 +0000 (+0000) Subject: Created script to automate blogpost creation X-Git-Url: http://source.bookstackapp.com/devops/commitdiff_plain/5787a151bc1af63457bcaecf871095b177a4b9d7 Created script to automate blogpost creation --- diff --git a/meta-scripts/bookstack-new-release-blogpost b/meta-scripts/bookstack-new-release-blogpost new file mode 100644 index 0000000..a696e01 --- /dev/null +++ b/meta-scripts/bookstack-new-release-blogpost @@ -0,0 +1,103 @@ +#!/usr/bin/env php +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 = "beta-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 = <<Header Image Credits: Photo by {$image->user->name} on Unsplash +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; +} \ No newline at end of file