Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
erikaheidi committed Jun 9, 2021
1 parent c7359e2 commit 90c9a6c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions bin/gdaisy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require $root_app . '/vendor/autoload.php';

$gdaisy = new App([
'app_debug' => true,
'default_template' => $root_app . '/resources/templates/article_preview.json',
'default_template' => __DIR__ . '/../resources/templates/article_preview.json',
]);

$input = new CommandCall($argv);
Expand Down Expand Up @@ -55,12 +55,21 @@ $gdaisy->registerCommand('generate', function() use ($gdaisy, $input) {

$url = $input->args[2];
$dest = $input->args[3];

$tags = get_meta_tags($url);

$image_file = __DIR__ . '/../resources/images/gdaisy.png';
$image_url = $tags['twitter:image'] ?? $tags['twitter:image:src'] ?? null;
if ($image_url) {
$image_file = Util::downloadImage($image_url);
}

$title = $tags['twitter:title'] ?? get_page_title($url) ?? 'Gdaisy';
$description = $tags['twitter:description'] ?? $tags['description'] ?? 'Generated with erikaheidi/gdaisy';
$elements = [
'title' => [ "text" => html_entity_decode($tags['twitter:title'], ENT_QUOTES) ],
'description' => [ "text" => html_entity_decode($tags['twitter:description'], ENT_QUOTES) . "..." ],
'thumbnail' => [ "image_file" => Util::downloadImage($tags['twitter:image'] ?? $tags['twitter:image:src'])]
'title' => [ "text" => html_entity_decode($title, ENT_QUOTES) ],
'description' => [ "text" => html_entity_decode($description, ENT_QUOTES) ],
'thumbnail' => [ "image_file" => $image_file]
];

$template->build($elements);
Expand All @@ -77,3 +86,16 @@ try {
$gdaisy->getPrinter()->error("Command not found.");
return 1;
}

function get_page_title(string $url) {
$dom = new \DOMDocument();

if(@$dom->loadHTMLFile($url)) {
$list = $dom->getElementsByTagName("title");
if ($list->length > 0) {
return $list->item(0)->textContent;
}
}

return null;
}
Binary file added resources/images/gdaisy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 90c9a6c

Please sign in to comment.