From 4a40b41f386af23da54cd35b8abac1f27c8e5ef7 Mon Sep 17 00:00:00 2001 From: "David T. Sadler" Date: Mon, 8 Nov 2021 20:50:15 +0000 Subject: Filter by tag --- public/css/site.css | 5 +++++ src/DTS/BookmarkRepository.php | 13 +++++++++++++ src/templates/index.php | 9 +++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/public/css/site.css b/public/css/site.css index 6204f7b..e689de7 100644 --- a/public/css/site.css +++ b/public/css/site.css @@ -58,6 +58,7 @@ a.no-decoration:before { content: ""; } +ul, ol { list-style-type: none; padding: 0; @@ -102,6 +103,10 @@ button { text-align: center; } +.tag { + color: #86EFAC; +} + @media (min-width: 1536px) { section { width: 80%; diff --git a/src/DTS/BookmarkRepository.php b/src/DTS/BookmarkRepository.php index 01f6de4..fde8510 100644 --- a/src/DTS/BookmarkRepository.php +++ b/src/DTS/BookmarkRepository.php @@ -12,6 +12,8 @@ class BookmarkRepository implements \Iterator private array $repository = []; + private array $tags = []; + private int $position = 0; function __construct(string $pathToRepository) @@ -75,6 +77,11 @@ class BookmarkRepository implements \Iterator return false; } + public function tags(): array + { + return $this->tags; + } + public function current(): mixed { return $this->repository[$this->position]; @@ -122,8 +129,14 @@ class BookmarkRepository implements \Iterator $bookmark->addedAt = $data[3]; $this->repository[] = $bookmark; + + $this->tags[] = $bookmark->tag; } + $this->tags = array_filter(array_unique($this->tags)); + + sort($this->tags); + fclose($fp); } diff --git a/src/templates/index.php b/src/templates/index.php index c046e6c..796bc26 100644 --- a/src/templates/index.php +++ b/src/templates/index.php @@ -15,11 +15,16 @@ Add Bookmark

Tags

- All +

Bookmarks

    -
  1. addedAt))->format('Y-m-d'); ?> - title != '' ? htmlentities($bookmark->title) : htmlentities($bookmark->url); ?> | Edit | Delete
  2. +
  3. addedAt))->format('Y-m-d'); ?> - title != '' ? htmlentities($bookmark->title) : htmlentities($bookmark->url); ?> | tag) { ?>tag); ?> | Edit | Delete

Copyright © 2021 David T. Sadler.

-- cgit v1.2.3-13-gbd6f