Skip to content

Commit

Permalink
Merge pull request #5 from rafaeldelboni/feat/add-hidden-page
Browse files Browse the repository at this point in the history
feat: Adds hidden pages from list
  • Loading branch information
rafaeldelboni authored Oct 31, 2021
2 parents 9ef882b + 2800137 commit bab0b50
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ New:

Create? (Y/n):
```
> Is possible to create "hidden" pages adding `--hide` to the command, this will filter the page from pages list resolver, but anyone will stil be able to access it via url/slug.
### Delete Page
```bash
Expand Down
3 changes: 3 additions & 0 deletions resources/public/pages/hidden-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Secret

This page is hidden in the page list resolver, but as you can see accessible via direct url.
2 changes: 2 additions & 0 deletions resources/public/pages/home.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ New:
Create? (Y/n):
```

> Is possible to create "hidden" pages adding `--hide` to the command, this will filter the page from pages list resolver, but anyone will stil be able to access it via [url/slug](#/hidden-page)
### Delete Page
```bash
bb del:page about
Expand Down
19 changes: 12 additions & 7 deletions scripts/nota/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
:post/tags (-> tags (string/split #" ") set)})

(defn args->new-page
[{:keys [new-name]} resource-path]
[{:keys [new-name hidden]
:or {hidden false}} resource-path]
{:page/name new-name
:page/path (string/join "/" (drop 2 resource-path))})
:page/path (string/join "/" (drop 2 resource-path))
:page/hidden hidden})

(defn args->new-tag
[{:keys [new-name]}]
Expand Down Expand Up @@ -201,9 +203,10 @@ Usage:
new:page -h | --help
Options:
-h --help Show help.
-n --name <name> page name.
-s --slug <slug> page slug override. [Optional]
-h --help Show help.
-n --name <name> page name.
-s --slug <slug> page slug override. [Optional]
--hide page isn't listed, but still accessible via slug. [Optional]
")

(defn new-page
Expand All @@ -216,9 +219,11 @@ Options:
(println new-page-doc)
(System/exit 0))
(let [new-name (or (arg-map "<name>") (arg-map "--name"))
slug (arg-map "--slug")]
slug (arg-map "--slug")
hidden (arg-map "--hide")]
(new-item-action {:new-name new-name
:slug slug}
:slug slug
:hidden hidden}
:pages)))))

(def del-page-doc "Nota: New page
Expand Down
15 changes: 14 additions & 1 deletion scripts/nota/tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,21 @@

(deftest args-new-page-test
(is (= {:page/name "A Link To The Past"
:page/path "games"}
:page/path "games"
:page/hidden false}
(main/args->new-page {:new-name "A Link To The Past"}
["res" "pub" "games"])))
(is (= {:page/name "A Link To The Past"
:page/path "games"
:page/hidden false}
(main/args->new-page {:new-name "A Link To The Past"
:hidden false}
["res" "pub" "games"])))
(is (= {:page/name "A Link To The Past The Hidden Bootleg"
:page/path "games"
:page/hidden true}
(main/args->new-page {:new-name "A Link To The Past The Hidden Bootleg"
:hidden true}
["res" "pub" "games"]))))

(deftest args-new-tag-test
Expand Down
3 changes: 2 additions & 1 deletion src/data.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{:pages {"home" {:page/name "Home", :page/path "pages/home.md"}
"about" {:page/name "About", :page/path "pages/about.md"}}
"about" {:page/name "About", :page/path "pages/about.md"}
"hidden-page" {:page/name "Secret", :page/path "pages/hidden-page.md", :page/hidden true}}

:posts {"hello-world" {:post/name "Hello World", :post/description "Such hello, much world", :post/timestamp 1635101110744, :post/path "posts/hello-world.md", :post/tags #{"markdown" "first"}}
"gfm-syntax" {:post/name "GFM Syntax", :post/description "All about Github Markdown Syntax", :post/timestamp 1635538866761, :post/path "posts/gfm-syntax.md", :post/tags #{"markdown"}}}
Expand Down
7 changes: 7 additions & 0 deletions src/nota/logics.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
(contains? (tag-key val) tag-id)))
(into {})))

(defn filter-by
[list-to-filter by-fn]
(->> list-to-filter
(filter (fn [[_key val]]
(by-fn val)))
(into {})))

(defn get-tag-override
[tags id]
(or (get tags id)
Expand Down
1 change: 1 addition & 0 deletions src/nota/resolvers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
:page/path]}]}
{:list-pages (-> :pages
database-fn
(logics/filter-by (comp not :page/hidden))
(adapters/hashmap->map-list-id :page/id))})

(pc/defresolver list-posts-resolver [{:keys [database-fn]} _]
Expand Down
10 changes: 10 additions & 0 deletions test/nota/logics_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@
(is (= (logics/filter-by-tag fixture :post/tags :c)
{"post-3" {:post/name "Post 3" :post/tags #{:a :b :c}}}))))

(deftest filter-by-test
(let [fixture {"page-1" {:page/name "page 1"}
"page-2" {:page/name "page 2" :page/hidden false}
"page-3" {:page/name "page 3" :page/hidden true}}]
(is (= (logics/filter-by fixture :page/hidden)
{"page-3" {:page/name "page 3" :page/hidden true}}))
(is (= (logics/filter-by fixture (comp not :page/hidden))
{"page-1" {:page/name "page 1"}
"page-2" {:page/name "page 2" :page/hidden false}}))))

(deftest order-by-desc-test
(let [fixture [{:post/name "Post 1" :post/timestamp 1}
{:post/name "Post 2" :post/timestamp 2}
Expand Down

0 comments on commit bab0b50

Please sign in to comment.