diff options
Diffstat (limited to 'tissue/file-document.scm')
-rw-r--r-- | tissue/file-document.scm | 63 |
1 files changed, 24 insertions, 39 deletions
diff --git a/tissue/file-document.scm b/tissue/file-document.scm index b910131..f389976 100644 --- a/tissue/file-document.scm +++ b/tissue/file-document.scm @@ -1,5 +1,5 @@ ;;; tissue --- Text based issue tracker -;;; Copyright © 2022 Arun Isaac <arunisaac@systemreboot.net> +;;; Copyright © 2022, 2023 Arun Isaac <arunisaac@systemreboot.net> ;;; ;;; This file is part of tissue. ;;; @@ -38,6 +38,7 @@ file-document-created-date file-document-last-updater file-document-last-updated-date + commits-affecting-file read-gemtext-document)) (define-class <file-document> (<document>) @@ -58,7 +59,7 @@ (compose doc:commit-author-date last file-document-commits)) (define-method (document-type (document <file-document>)) - (next-method)) + "document") (define-method (document-id-term (document <file-document>)) "Return the ID term for DOCUMENT." @@ -68,10 +69,14 @@ "Return a date representing the recency of DOCUMENT." (file-document-last-updated-date document)) +(define (file-text file) + "Return the contents of text @var{file}." + (call-with-input-file file + get-string-all)) + (define-method (document-text (document <file-document>)) "Return the full text of DOCUMENT." - (call-with-file-in-git (current-git-repository) (file-document-path document) - get-string-all)) + (file-text (file-document-path document))) (define-method (document-term-generator (document <file-document>)) "Return a term generator indexing DOCUMENT." @@ -116,40 +121,25 @@ MSet object representing a list of search results." (newline port) (newline port)))) -(define-method (document->sxml (document <file-document>) mset) - "Render DOCUMENT to SXML. MSET is the xapian MSet object representing -a list of search results." - `(li (@ (class "search-result search-result-document")) - (a (@ (href ,(document-web-uri document)) - (class "search-result-title")) - ,(document-title document)) - (div (@ (class "search-result-metadata")) - (span (@ (class ,(string-append "document-type file-document-type"))) - "document") - ,(string-append - (format #f " created ~a by ~a" - (human-date-string (file-document-created-date document)) - (file-document-creator document)) - (if (> (length (file-document-commits document)) - 1) - (format #f ", last updated ~a by ~a" - (human-date-string (file-document-last-updated-date document)) - (file-document-last-updater document)) - ""))) - ,@(let ((snippet (document-sxml-snippet document mset))) - (if snippet - (list `(div (@ (class "search-result-snippet")) - ,@snippet)) - (list))))) - (define file-modification-table-for-current-repository (memoize-thunk (cut file-modification-table (current-git-repository)))) +(define (commits-affecting-file file) + "Return a list of commits affecting @var{file} in current repository." + (map (lambda (commit) + (make <commit> + #:author (resolve-alias (signature-name (commit-author commit)) + (%aliases)) + #:author-date (commit-author-date commit))) + (hashtable-ref (file-modification-table-for-current-repository) + file #f))) + (define (read-gemtext-document file) - "Read gemtext document from FILE. Return a <file-document> object." + "Read gemtext document from @var{file} and return a +@code{<file-document>} object." (make <file-document> - #:title (or (call-with-file-in-git (current-git-repository) file + #:title (or (call-with-input-file file (lambda (port) (port-transduce (tfilter-map (lambda (line) ;; The first level one @@ -162,10 +152,5 @@ a list of search results." ;; Fallback to filename if document has no title. file) #:path file - #:commits (map (lambda (commit) - (make <commit> - #:author (resolve-alias (signature-name (commit-author commit)) - (%aliases)) - #:author-date (commit-author-date commit))) - (hashtable-ref (file-modification-table-for-current-repository) - file #f)))) + #:commits (commits-affecting-file file) + #:snippet-source-text (file-text file))) |