diff options
author | Alexander_Kabui | 2024-07-26 00:40:18 +0300 |
---|---|---|
committer | Alexander_Kabui | 2024-07-26 00:40:18 +0300 |
commit | f512c09215ecf2eeaded5ba0c7e52192344d2add (patch) | |
tree | b15fb7594fd10861fa32c12514b43286ab86ff15 /web | |
parent | 4b2af17b1c131c7ca5c150ece88406fcf64d9fc6 (diff) | |
download | gn-guile-f512c09215ecf2eeaded5ba0c7e52192344d2add.tar.gz |
Add fetch file procedure.
Diffstat (limited to 'web')
-rw-r--r-- | web/view/markdown.scm | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/web/view/markdown.scm b/web/view/markdown.scm index 2af2b26..fac9a98 100644 --- a/web/view/markdown.scm +++ b/web/view/markdown.scm @@ -6,24 +6,28 @@ #:use-module (ice-9 receive) #:use-module (ice-9 string-fun) #:use-module (ice-9 textual-ports) + #:use-module (ice-9 exceptions) #:use-module (sxml simple) #:use-module (web client) #:use-module (web uri) #:use-module (web request) + #:use-module (web sxml) #:use-module (commonmark) #:export (markdown-file->sxml markdown-github->sxml + fetch-file fetch-raw-file) ) + (define (markdown-file->sxml fn) "Parse a local file" (commonmark->sxml (call-with-input-file fn - get-string-all))) + get-string-all))) ;; --- fetch github style URLs @@ -53,3 +57,16 @@ (a (@ (href ,(form-github-edit-url project repo page)) (role "button")) "edit"))) (br) (br)))) + + + +(define (fetch-file repo query_path) + (let* ( (abs_path (string-append repo "/" query_path))) + (if (file-exists? abs_path) (let* ((full_path (canonicalize-path abs_path)) + (content (call-with-input-file full_path get-string-all)) + ) + `(("path" . ,query_path) + ("content" . ,content) + ("hash" . "commit hash here")) + ) (throw 'file-error (string-append "the file path " abs_path " does not exists"))) + )) |