aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThedro Neely <thedroneely@gmail.com>2022-04-02 04:11:04 -0400
committerThedro Neely <thedroneely@gmail.com>2022-04-02 04:11:04 -0400
commit40e1ea11041031dd65be0a0541cad0b2dda71d3e (patch)
tree837649099e80faf1b8c69ddb4f96b4634aee519b
parent53733f7d389f84174b6c4294a24d3ab70b852d5d (diff)
downloadthedroneely.com-40e1ea11041031dd65be0a0541cad0b2dda71d3e.tar.gz
thedroneely.com-40e1ea11041031dd65be0a0541cad0b2dda71d3e.tar.bz2
thedroneely.com-40e1ea11041031dd65be0a0541cad0b2dda71d3e.zip
app/model/HTMLExtract: Simplify
Empty elements not supported in libxml2.
-rw-r--r--app/model/HTMLExtract.php61
-rw-r--r--app/views/index.view.php6
-rw-r--r--generators/hugo/themes/tdro/layouts/_default/section.html28
-rw-r--r--generators/hugo/themes/tdro/layouts/abstracts/section.html4
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("</source>", '', $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 @@
<?php
$recentPosts = new DOMExtract();
- $recentPosts->setSource($_SERVER['DOCUMENT_ROOT'] . '/posts/index.html');
- echo $recentPosts->getInnerHTML('recent-article');
+ echo $recentPosts->innerHTML('recent-articles', $_SERVER['DOCUMENT_ROOT'] . '/posts/index.html');
?>
<a href="/posts/page/2/"
@@ -86,8 +85,7 @@
<?php
$recentProjects = new DOMExtract();
- $recentProjects->setSource($_SERVER['DOCUMENT_ROOT'] . '/projects/index.html');
- echo $recentProjects->getInnerHTML('recent-article');
+ echo $recentPosts->innerHTML('recent-articles', $_SERVER['DOCUMENT_ROOT'] . '/projects/index.html');
?>
</div>
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" }}
<section class="section is-fullheight" itemscope itemtype="https://schema.org/AboutPage">
- <div class="container">
- <div class="columns is-centered">
- <div class="column is-7">
- <article class="content">
- <br>
+ <div class="container">
+ <div class="columns is-centered">
+ <div class="column is-7">
+ <article class="content">
+ <br>
<span class="marginnote rightnote">
See an archive of all {{ .Type }} <a href="{{ partial "archive-link.html" . }}">here.</a>
</span>
- <recent-article>
- {{ range where .Paginator.Pages ".Params.hidden" "ne" "true" }}
- {{ .Render "summary" }}
- {{ end }}
- </recent-article>
+ <recent-articles>
+ {{ range where .Paginator.Pages ".Params.hidden" "ne" "true" }}
+ {{ .Render "summary" }}
+ {{ end }}
+ </recent-articles>
</article>
- {{ partial "pagination.html" . }}
+ {{ partial "pagination.html" . }}
<br>
<a href="{{ partial "archive-link.html" . }}" class="front__more is-block has-text-centered">
<span>Archive of all {{ .Type }}</span> {{ safeHTML (readFile "public/css/icons/feather/corner-down-right.svg") }}
</a>
- </div>
- </div>
- </div>
+ </div>
+ </div>
+ </div>
</section>
{{ 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 @@
<span class="marginnote rightnote">
See an archive of all {{ .Type }} <a href="{{ partial "archive-link.html" . }}">here.</a>
</span>
- <recent-article>
+ <recent-articles>
<div class="abstract tile is-ancestor has-text-centered">
{{ range where .Paginator.Pages ".Params.hidden" "ne" "true" }}
{{ .Render "summary" }}
{{ end }}
</div>
- </recent-article>
+ </recent-articles>
</article>
{{ partial "pagination.html" . }}
<br>