Skip to content

Commit

Permalink
Fix alias not included in published subgraph
Browse files Browse the repository at this point in the history
Fixes #4143
  • Loading branch information
logseq-cldwalker committed Jun 6, 2023
1 parent c3aa16d commit bd45f30
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 18 additions & 1 deletion deps/publishing/src/logseq/publishing/db.cljs
Expand Up @@ -2,6 +2,8 @@
"Provides db fns and associated util fns for publishing"
(:require [datascript.core :as d]
[logseq.db.schema :as db-schema]
[logseq.db.rules :as rules]
[clojure.set :as set]
[clojure.string :as string]))

(defn ^:api get-area-block-asset-url
Expand Down Expand Up @@ -92,6 +94,20 @@
flatten
distinct)))

(defn- get-aliases-for-page-ids
[db page-ids]
(->> (d/q '[:find ?e
:in $ ?pages %
:where
[?page :block/name]
[(contains? ?pages ?page)]
(alias ?page ?e)]
db
(set page-ids)
(:alias rules/rules))
(map first)
set))

(defn clean-export!
"Prepares a database assuming all pages are public unless a page has a 'public:: false'"
[db]
Expand All @@ -113,7 +129,8 @@
"Prepares a database assuming all pages are private unless a page has a 'public:: true'"
[db]
(when-let [public-pages* (seq (get-public-pages db))]
(let [public-pages (set public-pages*)
(let [public-pages (set/union (set public-pages*)
(get-aliases-for-page-ids db public-pages*))
exported-namespace? #(contains? #{"block" "recent"} %)
filtered-db (d/filter db
(fn [db datom]
Expand Down
4 changes: 3 additions & 1 deletion deps/publishing/test/logseq/publishing/db_test.cljs
Expand Up @@ -36,7 +36,7 @@
(deftest filter-only-public-pages-and-blocks
(let [conn (ldb/start-conn)
_ (graph-parser/parse-file conn "page1.md" "- b11\n- b12\n- ![awesome.png](../assets/awesome_1648822509908_0.png)")
_ (graph-parser/parse-file conn "page2.md" "public:: true\n- b21\n- ![thumb-on-fire.PNG](../assets/thumb-on-fire_1648822523866_0.PNG)")
_ (graph-parser/parse-file conn "page2.md" "alias:: page2-alias\npublic:: true\n- b21\n- ![thumb-on-fire.PNG](../assets/thumb-on-fire_1648822523866_0.PNG)")
_ (graph-parser/parse-file conn "page3.md" "public:: true\n- b31")
[filtered-db assets] (publish-db/filter-only-public-pages-and-blocks @conn)
exported-pages (->> (d/q '[:find (pull ?b [*])
Expand All @@ -56,6 +56,8 @@
"Contains all pages that have been marked public")
(is (not (contains? exported-pages "page1"))
"Doesn't contain private page")
(is (seq (d/entity filtered-db [:block/name "page2-alias"]))
"Alias of public page is exported")
(is (= #{"page2" "page3"} exported-block-pages)
"Only exports blocks from public pages")
(is (= ["thumb-on-fire_1648822523866_0.PNG"] assets)
Expand Down

0 comments on commit bd45f30

Please sign in to comment.