From 700710df5662cf9d9e587f92beae99acacbf1083 Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Fri, 6 Jun 2025 12:38:29 +0200 Subject: [PATCH] scrape old snippets --- deps.edn | 8 ++++++-- src/snippets/backfill.clj | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/snippets/backfill.clj diff --git a/deps.edn b/deps.edn index d8a5e68..14cbeac 100644 --- a/deps.edn +++ b/deps.edn @@ -8,11 +8,15 @@ com.xtdb/xtdb-api {:mvn/version "2.0.0-beta9"} com.github.seancorfield/next.jdbc {:mvn/version "1.3.1002"} org.postgresql/postgresql {:mvn/version "42.7.6"} + frontmatter/frontmatter {:mvn/version "0.0.1"} -;; json decoding + ;; schema validation + metosin/malli {:mvn/version "0.18.0"} + + ;; json decoding metosin/muuntaja {:mvn/version "0.6.11"} -;; routing: + ;; routing: metosin/reitit {:mvn/version "0.9.1"} ;; convenient package of "default" middleware: diff --git a/src/snippets/backfill.clj b/src/snippets/backfill.clj new file mode 100644 index 0000000..4a1a488 --- /dev/null +++ b/src/snippets/backfill.clj @@ -0,0 +1,25 @@ +(ns snippets.backfill + (:require + [clojure.java.io :as io] + [clojure.pprint :as pprint] + [clojure.string :as str] + [frontmatter.core :as fm])) + +(defn scrape-files [] + (let [dir "./old_snippets"] + (->> (io/file dir) + (.listFiles) + (map #(.getName %)) + (map #(hash-map :slug (first (str/split % #"\.")) :full-path (str dir "/" %))) + ;; (map #(fm/parse (:full-path %)))))) + (map #(let [{frontmatter :frontmatter body :body} (fm/parse (:full-path %))] + (assoc % + :title (:title frontmatter) + :pub-date (:date frontmatter) + :markdown body + :scraped true + :tags (:snippet_types frontmatter)))) + (map #(dissoc % :full-path))))) + +;; create snippets from files +;; save snippets in db