From 52951ecd3cc738939188c51792046ee285e1125d Mon Sep 17 00:00:00 2001 From: Erika Heidi Date: Sun, 14 Nov 2021 16:24:34 +0100 Subject: [PATCH] Improving support to custom images and templates (#17) * Updated Twitter controller for more flexibility with images and templates * Improving support for GitHub Actions with custom images and templates --- .env.example | 13 ++++++++++++- app/Command/Generate/TwitterController.php | 15 +++++++-------- app/Resources/templates/cover_basic.json | 2 +- app/Resources/templates/cover_colorful.json | 2 +- app/Resources/templates/cover_neon.json | 2 +- app/Resources/templates/cover_sponsors.json | 2 +- config_sample.php | 17 +++++++++++------ 7 files changed, 34 insertions(+), 19 deletions(-) diff --git a/.env.example b/.env.example index c89a373..cb59cc4 100644 --- a/.env.example +++ b/.env.example @@ -1,9 +1,20 @@ +############################# # Credentials +############################# TW_CONSUMER_KEY= TW_CONSUMER_SECRET= TW_USER_TOKEN= TW_USER_TOKEN_SECRET= GITHUB_TOKEN= +############################ +# Paths +############################ +DYNA_TEMPLATES_DIR= +DYNA_IMAGES_DIR= +DYNA_OUTPUT_DIR= + +################################## # Default Template -DEFAULT_TEMPLATE=app/Resources/templates/cover_basic.json \ No newline at end of file +################################## +#DYNA_DEFAULT_TEMPLATE=cover_sponsors.json \ No newline at end of file diff --git a/app/Command/Generate/TwitterController.php b/app/Command/Generate/TwitterController.php index 57fcc2d..add8173 100644 --- a/app/Command/Generate/TwitterController.php +++ b/app/Command/Generate/TwitterController.php @@ -13,21 +13,24 @@ class TwitterController extends CommandController { public function handle(): int { + $template_dir = $this->getApp()->config->templates_dir; $template_file = $this->getApp()->config->default_template; + $images_dir = $this->getApp()->config->images_dir; + $output_dir = $this->getApp()->config->output_dir; if ($this->hasParam('template')) { $template_file = $this->getParam('template'); } if (!is_file($template_file)) { - $template_file = Storage::root() . '/app/Resources/templates/' . $template_file; + $template_file = $template_dir . '/' . $template_file; if (!is_file($template_file)) { - $this->getPrinter()->error("Template not found."); + $this->getPrinter()->error("Template $template_file not found."); return 1; } } - $save_path = Storage::root() . 'latest_header.png'; + $save_path = $output_dir. '/latest_header.png'; $template = Template::create($template_file); $featured = []; @@ -47,12 +50,8 @@ public function handle(): int if ($placeholder instanceof ImagePlaceholder and $placeholder->image) { $resource_image = $placeholder->image; - if (filter_var($placeholder->image, FILTER_VALIDATE_URL)) { - $resource_image = Storage::downloadImage($placeholder->image); - } - if (!is_file($resource_image)) { - $resource_image = Storage::root() . $placeholder->image; + $resource_image = $images_dir . '/' . $placeholder->image; } $placeholder->apply($template->getResource(), ['image_file' => $resource_image]); diff --git a/app/Resources/templates/cover_basic.json b/app/Resources/templates/cover_basic.json index 6b13498..f84028c 100644 --- a/app/Resources/templates/cover_basic.json +++ b/app/Resources/templates/cover_basic.json @@ -60,7 +60,7 @@ "height": 500, "pos_x": 0, "pos_y": 0, - "image": "app/Resources/images/cover_basic.png" + "image": "cover_basic.png" } } } diff --git a/app/Resources/templates/cover_colorful.json b/app/Resources/templates/cover_colorful.json index 14ca1e6..b3e62ff 100644 --- a/app/Resources/templates/cover_colorful.json +++ b/app/Resources/templates/cover_colorful.json @@ -60,7 +60,7 @@ "height": 500, "pos_x": 0, "pos_y": 0, - "image": "app/Resources/images/cover_colorful.png" + "image": "cover_colorful.png" } } } diff --git a/app/Resources/templates/cover_neon.json b/app/Resources/templates/cover_neon.json index eccb86e..6e91f3b 100644 --- a/app/Resources/templates/cover_neon.json +++ b/app/Resources/templates/cover_neon.json @@ -60,7 +60,7 @@ "height": 500, "pos_x": 0, "pos_y": 0, - "image": "app/Resources/images/cover_neon.png" + "image": "cover_neon.png" } } } diff --git a/app/Resources/templates/cover_sponsors.json b/app/Resources/templates/cover_sponsors.json index 86c011a..8caaa15 100644 --- a/app/Resources/templates/cover_sponsors.json +++ b/app/Resources/templates/cover_sponsors.json @@ -82,7 +82,7 @@ "height": 500, "pos_x": 0, "pos_y": 0, - "image": "app/Resources/images/cover_sponsors.png" + "image": "cover_sponsors.png" } } } diff --git a/config_sample.php b/config_sample.php index feaf1d7..1512d56 100644 --- a/config_sample.php +++ b/config_sample.php @@ -2,14 +2,19 @@ return [ //Twitter API Keys - 'twitter_consumer_key' => getenv('TW_CONSUMER_KEY') ?: 'APP_CONSUMER_KEY', - 'twitter_consumer_secret' => getenv('TW_CONSUMER_SECRET') ?: 'APP_CONSUMER_SECRET', - 'twitter_user_token' => getenv('TW_USER_TOKEN') ?: 'USER_ACCESS_TOKEN', - 'twitter_token_secret' => getenv('TW_USER_TOKEN_SECRET') ?: 'USER_ACCESS_TOKEN_SECRET', + 'twitter_consumer_key' => getenv('DYNA_TWITTER_KEY') ?: 'APP_CONSUMER_KEY', + 'twitter_consumer_secret' => getenv('DYNA_TWITTER_SECRET') ?: 'APP_CONSUMER_SECRET', + 'twitter_user_token' => getenv('DYNA_TWITTER_TOKEN') ?: 'USER_ACCESS_TOKEN', + 'twitter_token_secret' => getenv('DYNA_TWITTER_TOKEN_SECRET') ?: 'USER_ACCESS_TOKEN_SECRET', //GitHub Personal Token (for templates using GH Sponsors) - 'github_api_bearer' => getenv('GITHUB_TOKEN') ?: 'GITHUB_API_BEARER_TOKEN', + 'github_api_bearer' => getenv('DYNA_GITHUB_TOKEN') ?: 'GITHUB_API_BEARER_TOKEN', + + //Paths + 'templates_dir' => getenv('DYNA_TEMPLATES_DIR') ?: __DIR__ . '/app/Resources/templates', + 'images_dir' => getenv('DYNA_IMAGES_DIR') ?: __DIR__ . '/app/Resources/images', + 'output_dir' => getenv('DYNA_OUTPUT_DIR') ?: __DIR__, //Default Template - 'default_template' => getenv('DEFAULT_TEMPLATE') ?: 'app/Resources/templates/cover_basic.json' + 'default_template' => getenv('DYNA_DEFAULT_TEMPLATE') ?: 'cover_basic.json' ]; \ No newline at end of file