瀏覽代碼

fix: renaming a page without TITLE eats characters of the first line

Related to #1510
Tienson Qin 4 年之前
父節點
當前提交
58980188a8

+ 1 - 0
src/main/frontend/components/page.cljs

@@ -276,6 +276,7 @@
               {:keys [title] :as properties} (:page/properties page)
               page-name (:page/name page)
               page-original-name (:page/original-name page)
+              title (or title page-original-name page-name)
               file (:page/file page)
               file-path (and (:db/id file) (:file/path (db/entity repo (:db/id file))))
               today? (and

+ 12 - 5
src/main/frontend/format/block.cljs

@@ -313,7 +313,9 @@
 (defn safe-blocks
   [blocks]
   (map (fn [block]
-         (block-keywordize (util/remove-nils block)))
+         (if (map? block)
+           (block-keywordize (util/remove-nils block))
+           block))
        blocks))
 
 (defn with-path-refs
@@ -355,7 +357,8 @@
 
 (defn extract-blocks
   [blocks last-pos encoded-content]
-  (let [blocks
+  (let [pre-block-body (atom nil)
+        blocks
         (loop [headings []
                block-body []
                blocks (reverse blocks)
@@ -425,8 +428,11 @@
                 :else
                 (let [block-body' (conj block-body block)]
                   (recur headings block-body' (rest blocks) timestamps properties last-pos last-level children))))
-            (-> (reverse headings)
-                safe-blocks)))]
+            (do
+              (when (seq block-body)
+                (reset! pre-block-body block-body))
+              (-> (reverse headings)
+                  safe-blocks))))]
     (let [first-block (first blocks)
           first-block-start-pos (get-in first-block [:block/meta :start-pos])
           blocks (if (and
@@ -445,7 +451,8 @@
                          :meta {:start-pos 0
                                 :end-pos (or first-block-start-pos
                                              (utf8/length encoded-content))}
-                         :body (take-while (fn [block] (not (heading-block? block))) blocks)
+                         :body @pre-block-body
+                         ;; (take-while (fn [block] (not (heading-block? block))) blocks)
                          :pre-block? true}
                         (block-keywordize)))
                      (select-keys first-block [:block/file :block/format :block/page]))

+ 7 - 5
src/main/frontend/handler/block.cljs

@@ -147,11 +147,13 @@
           property-names (keys properties)]
       (and (every? #(contains? #{:title :filters} %) property-names)
            (let [ast (mldoc/->edn (:block/content block) (mldoc/default-config (:block/format block)))]
-             (or
-              (empty? (rest ast))
-              (every? (fn [[[typ break-lines]] _]
-                        (and (= typ "Paragraph")
-                             (every? #(= % ["Break_Line"]) break-lines))) (rest ast))))))))
+             (and
+              (= "Properties" (ffirst (first ast)))
+              (or
+               (empty? (rest ast))
+               (every? (fn [[[typ break-lines]] _]
+                         (and (= typ "Paragraph")
+                              (every? #(= % ["Break_Line"]) break-lines))) (rest ast)))))))))
 
 (defn with-dummy-block
   ([blocks format]

+ 4 - 4
src/main/frontend/handler/page.cljs

@@ -98,15 +98,15 @@
     (if file
       (let [page-format (db/get-page-format page-name)
             properties-content (db/get-page-properties-content page-name)
-            properties-content (if properties-content
-                                 (string/trim properties-content)
-                                 (config/properties-wrapper page-format))
             file (db/entity (:db/id (:page/file page)))
             file-path (:file/path file)
             file-content (db/get-file file-path)
-            after-content (if (empty? properties-content)
+            after-content (if (string/blank? properties-content)
                             file-content
                             (subs file-content (inc (count properties-content))))
+            properties-content (if properties-content
+                                 (string/trim properties-content)
+                                 (config/properties-wrapper page-format))
             new-properties-content (db/add-properties! page-format properties-content properties)
             full-content (str new-properties-content "\n\n" (string/trim after-content))]
         (file-handler/alter-file (state/get-current-repo)