From 213b33b9b544869188842281842ca35996b7d515 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Goetz?= Date: Fri, 24 Apr 2020 22:22:57 +0200 Subject: [PATCH] Support Plausible.io Analytics --- .github/workflows/php.yml | 2 +- docs/05_Configuration/Html_export.md | 9 +++++ docs/_index.md | 15 -------- docs/config.json | 4 +- libs/ConfigBuilder.php | 15 +++++--- libs/Format/HTML/Config.php | 10 +++++ templates/layout/00_layout.php | 43 +++++++++++++--------- templates/partials/plausible_analytics.php | 1 + 8 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 templates/partials/plausible_analytics.php diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 59ee060..2694ce3 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -77,7 +77,7 @@ jobs: - name: Install dependencies run: composer install --prefer-dist --no-progress --no-suggest - name: Generate documentation - run: bin/daux generate + run: bin/daux generate --value html.plausible_domain=daux.io - uses: JamesIves/github-pages-deploy-action@2.0.3 env: FOLDER: "static" diff --git a/docs/05_Configuration/Html_export.md b/docs/05_Configuration/Html_export.md index 4175751..48c868c 100644 --- a/docs/05_Configuration/Html_export.md +++ b/docs/05_Configuration/Html_export.md @@ -30,6 +30,15 @@ You can Also give a specific Piwik ID as well. } ``` +### Plausible Analytics +This will embed the https://plausible.io/ tracking code. + +```json +{ + "html": { "plausible_domain": "daux.io" } +} +``` + ## Automatic Table of Contents You can add a table of contents on each page automatically, read about it [here](../01_Features/Table_of_contents.md) diff --git a/docs/_index.md b/docs/_index.md index c42b25d..344331b 100644 --- a/docs/_index.md +++ b/docs/_index.md @@ -69,18 +69,3 @@ docker run --rm -it -w /build -v "$PWD":/build daux/daux.io daux generate ``` --- - - - - - - diff --git a/docs/config.json b/docs/config.json index 5d17c32..6487172 100644 --- a/docs/config.json +++ b/docs/config.json @@ -21,13 +21,13 @@ "repo": "dauxio/daux.io", "edit_on_github": "dauxio/daux.io/blob/master/docs", "twitter": ["onigoetz"], - "google_analytics": "UA-3551397-7", + "google_analytics": false, + "plausible_domain": false, "links": { "Download": "https://github.com/dauxio/daux.io/archive/master.zip", "GitHub Repo": "https://github.com/dauxio/daux.io", "Help/Support/Bugs": "https://github.com/dauxio/daux.io/issues" }, - "powered_by": "Powered by Daux.io" }, "confluence": { diff --git a/libs/ConfigBuilder.php b/libs/ConfigBuilder.php index b904efe..473effc 100644 --- a/libs/ConfigBuilder.php +++ b/libs/ConfigBuilder.php @@ -5,6 +5,9 @@ class ConfigBuilder /** @var Config */ private $config; + /** @var array */ + private $overrideValues = []; + private $configuration_override_file; private function __construct(string $mode) @@ -34,7 +37,7 @@ class ConfigBuilder return $this; } - private function setValue(&$array, $key, $value) + private function setValue(Config $array, $key, $value) { if (is_null($key)) { return $array = $value; @@ -48,15 +51,11 @@ class ConfigBuilder $array = &$array[$key]; } $array[array_shift($keys)] = $value; - - return $array; } public function withValues(array $values): ConfigBuilder { - foreach ($values as $value) { - $this->setValue($this->config, $value[0], $value[1]); - } + $this->overrideValues = $values; return $this; } @@ -128,6 +127,10 @@ class ConfigBuilder { $this->initializeConfiguration(); + foreach ($this->overrideValues as $value) { + $this->setValue($this->config, $value[0], $value[1]); + } + return $this->config; } diff --git a/libs/Format/HTML/Config.php b/libs/Format/HTML/Config.php index 8a40d37..cac9528 100644 --- a/libs/Format/HTML/Config.php +++ b/libs/Format/HTML/Config.php @@ -76,6 +76,16 @@ class Config extends BaseConfig return $this->getValue('google_analytics'); } + public function hasPlausibleAnalyticsDomain() + { + return $this->hasValue('plausible_domain') && $this->getValue('plausible_domain'); + } + + public function getPlausibleAnalyticsDomain() + { + return $this->getValue('plausible_domain'); + } + public function hasPiwikAnalytics() { return $this->getValue('piwik_analytics') && $this->hasValue('piwik_analytics_id'); diff --git a/templates/layout/00_layout.php b/templates/layout/00_layout.php index 80de567..c4f7297 100755 --- a/templates/layout/00_layout.php +++ b/templates/layout/00_layout.php @@ -2,19 +2,26 @@ <?= $page['title']; ?> <?= ($page['title'] != $config->getTitle()) ? '- ' . $config->getTitle() : "" ?> -\n"; + $meta['description'] = $page['attributes']['description']; } elseif ($config->hasTagline()) { - echo " getTagline()}\">\n"; + $meta['description'] = $config->getTagLine(); } if (array_key_exists('attributes', $page) && array_key_exists('keywords', $page['attributes'])) { - echo " \n"; + $meta['keywords'] = $page['attributes']['keywords']; } if (array_key_exists('attributes', $page) && array_key_exists('author', $page['attributes'])) { - echo " \n"; + $meta['author'] = $page['attributes']['author']; } elseif ($config->hasAuthor()) { - echo " getAuthor()}\">\n"; + $meta['author'] = $config->getAuthor(); + } + + foreach ($meta as $name => $content) { + echo " \n"; } ?> @@ -28,19 +35,19 @@ - getTheme()->getFonts() as $font) { - echo ""; -} ?> + getTheme()->getFonts() as $font) { ?> + + - getTheme()->getCSS() as $css) { - echo ""; -} ?> + getTheme()->getCSS() as $css) { ?> + + getHTML()->hasSearch()) { ?> @@ -57,14 +64,16 @@ if ($config->getHTML()->hasPiwikAnalytics()) { $this->insert('theme::partials/piwik_analytics', ['url' => $config->getHTML()->getPiwikAnalyticsUrl(), 'id' => $config->getHTML()->getPiwikAnalyticsId()]); } + if ($config->getHTML()->hasPlausibleAnalyticsDomain()) { + $this->insert('theme::partials/plausible_analytics', ['domain' => $config->getHTML()->getPlausibleAnalyticsDomain()]); + } ?> - getTheme()->getJS() as $js) { - echo ''; - } ?> + getTheme()->getJS() as $js) { ?> + + insert('theme::partials/search_script', ['page' => $page, 'base_url' => $base_url]); ?> - diff --git a/templates/partials/plausible_analytics.php b/templates/partials/plausible_analytics.php new file mode 100644 index 0000000..6141716 --- /dev/null +++ b/templates/partials/plausible_analytics.php @@ -0,0 +1 @@ +