Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

Improving support to custom images and templates #17

Merged
merged 4 commits into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -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
##################################
#DYNA_DEFAULT_TEMPLATE=cover_sponsors.json
15 changes: 7 additions & 8 deletions app/Command/Generate/TwitterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion app/Resources/templates/cover_basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"height": 500,
"pos_x": 0,
"pos_y": 0,
"image": "app/Resources/images/cover_basic.png"
"image": "cover_basic.png"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Resources/templates/cover_colorful.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"height": 500,
"pos_x": 0,
"pos_y": 0,
"image": "app/Resources/images/cover_colorful.png"
"image": "cover_colorful.png"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Resources/templates/cover_neon.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"height": 500,
"pos_x": 0,
"pos_y": 0,
"image": "app/Resources/images/cover_neon.png"
"image": "cover_neon.png"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/Resources/templates/cover_sponsors.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"height": 500,
"pos_x": 0,
"pos_y": 0,
"image": "app/Resources/images/cover_sponsors.png"
"image": "cover_sponsors.png"
}
}
}
Expand Down
17 changes: 11 additions & 6 deletions config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
];