From 40e1ea11041031dd65be0a0541cad0b2dda71d3e Mon Sep 17 00:00:00 2001 From: Thedro Neely Date: Sat, 2 Apr 2022 04:11:04 -0400 Subject: app/model/HTMLExtract: Simplify Empty elements not supported in libxml2. --- app/model/HTMLExtract.php | 61 ++++++---------------- app/views/index.view.php | 6 +-- .../hugo/themes/tdro/layouts/_default/section.html | 28 +++++----- .../themes/tdro/layouts/abstracts/section.html | 4 +- 4 files changed, 33 insertions(+), 66 deletions(-) diff --git a/app/model/HTMLExtract.php b/app/model/HTMLExtract.php index 5c3f727..b2ab39e 100644 --- a/app/model/HTMLExtract.php +++ b/app/model/HTMLExtract.php @@ -2,7 +2,6 @@ class DOMExtract extends DOMDocument { - private $source; private $document; public function __construct() @@ -10,55 +9,25 @@ class DOMExtract extends DOMDocument libxml_use_internal_errors(true); $this->preserveWhiteSpace = false; $this->strictErrorChecking = false; - $this->formatOutput = true; + $this->formatOutput = false; } - public function setSource($source) + public function innerHTML($tag, $file) { - $this->source = file_get_contents($source); - return $this; - } - - public function getInnerHTML($tag, $id=null, $nodeValue = false) - { - if (empty($this->source)) { - throw new Exception('Error: Missing $this->source, use setSource() first'); - } - - $html = null; - $this->loadHTML($this->source); - $element = $this->getElementsByTagName($tag); - - foreach ($element as $tags) { - if ($id !== null) { - $attr = explode('=', $id); - if ($tags->getAttribute($attr[0]) == $attr[1]) { - if ($nodeValue == true) { - $html .= trim($tags->nodeValue); - } else { - $html .= $this->innerHTML($tags); - } - } - } else { - if ($nodeValue == true) { - $html .= trim($tags->nodeValue); - } else { - $html .= $this->innerHTML($tags); - } - } + $html = ''; + $this->loadHTML(file_get_contents($file)); + $this->document = $this->getElementsByTagName($tag); + + foreach ($this->document as $node) + { + /* + | TODO: DOMDocument::saveHTML's empty elements list is not updated. + | https://bugs.php.net/bug.php?id=73175 + */ + + $html .= $this->saveHTML($node); } - return $html; - } - protected function innerHTML($document) - { - $html = ""; - foreach ($document->childNodes as $v) { - $tmp = new DOMDocument(); - $tmp->appendChild($tmp->importNode($v, true)); - $html .= trim($tmp->saveHTML()); - } - return $html; + return str_replace("", '', $html); } - } diff --git a/app/views/index.view.php b/app/views/index.view.php index 7c02198..1388848 100644 --- a/app/views/index.view.php +++ b/app/views/index.view.php @@ -61,8 +61,7 @@ setSource($_SERVER['DOCUMENT_ROOT'] . '/posts/index.html'); - echo $recentPosts->getInnerHTML('recent-article'); + echo $recentPosts->innerHTML('recent-articles', $_SERVER['DOCUMENT_ROOT'] . '/posts/index.html'); ?> setSource($_SERVER['DOCUMENT_ROOT'] . '/projects/index.html'); - echo $recentProjects->getInnerHTML('recent-article'); + echo $recentPosts->innerHTML('recent-articles', $_SERVER['DOCUMENT_ROOT'] . '/projects/index.html'); ?> diff --git a/generators/hugo/themes/tdro/layouts/_default/section.html b/generators/hugo/themes/tdro/layouts/_default/section.html index 889c158..adb5fbf 100644 --- a/generators/hugo/themes/tdro/layouts/_default/section.html +++ b/generators/hugo/themes/tdro/layouts/_default/section.html @@ -1,26 +1,26 @@ {{ define "main" }}
-
{{ end }} diff --git a/generators/hugo/themes/tdro/layouts/abstracts/section.html b/generators/hugo/themes/tdro/layouts/abstracts/section.html index bdd4c8d..b4121a2 100644 --- a/generators/hugo/themes/tdro/layouts/abstracts/section.html +++ b/generators/hugo/themes/tdro/layouts/abstracts/section.html @@ -8,13 +8,13 @@ See an archive of all {{ .Type }} here. - +
{{ range where .Paginator.Pages ".Params.hidden" "ne" "true" }} {{ .Render "summary" }} {{ end }}
-
+ {{ partial "pagination.html" . }}
-- cgit v1.2.3