Compare commits

...

9 Commits

5 changed files with 98 additions and 14 deletions

4
.dir-locals.el Normal file
View File

@ -0,0 +1,4 @@
;;; Directory Local Variables -*- no-byte-compile: t -*-
;;; For more information see (info "(emacs) Directory Variables")
((scheme-mode . ((tab-width . 4))))

View File

@ -2,3 +2,10 @@
#+TITLE: README for Guile Guile-Docs
Like janetdocs or clojuredocs, but for guile!
* Developing
** Guix
Just run src_bash{guix shell -Df guix.scm -m manifest.scm} to get a developer environment.
manifest.scm is intended for dev tools related programs.

View File

@ -0,0 +1,55 @@
;; Simplified guile web server outlined in
;; https://spritely.institute/files/docs/guile-hoot/0.2.0/Tutorial.html
(use-modules (ice-9 binary-ports) (ice-9 format) (ice-9 match)
(web server) (web request) (web response) (web uri)
(haunt html))
(define (extension file)
(match (string-split file #\.)
(() #f)
((_ ... ext) ext)))
(define (mime-type file-name)
(or (assoc-ref '(("js" . application/javascript)
("html" . text/html)
("scm" . text/stml)
("wasm" . application/wasm))
(extension file-name))
'text/plain))
(define (render-stml file-name)
(values '((content-type . (text/html)))
(sxml->html-string (load file-name))))
(define (render-file file-name)
(let ((type (mime-type file-name)))
(if (eq? type 'text/stml)
(render-stml file-name)
(values `((content-type . (,type)))
(call-with-input-file file-name get-bytevector-all)))))
(define (not-found path)
(values (build-response #:code 404) (string-append "Not found: " path)))
(define (directory? file-name)
(eq? (stat:type (stat file-name)) 'directory))
(define (serve-file path)
(define %prefix `(,(getcwd) "public"))
(define (prepend-prefix path) (string-join (append %prefix `(,path)) file-name-separator-string))
(let* ((f (prepend-prefix (uri-decode path))))
(cond ((and (file-exists? f) (not (directory? f)))
(render-file f))
((equal? "/" path)
(render-file (prepend-prefix "index.scm")))
(else not-found path))))
(define (handle-request request body)
(let ((method (request-method request))
(path (uri-path (request-uri request))))
(format #t "~a ~a\n" method path)
(serve-file path)))
(run-server handle-request 'http '(#:port 8080))

View File

@ -1,30 +1,42 @@
(use-modules
(guix packages)
((guix licenses) #:prefix license:)
(guix download)
(guix build-system gnu)
(gnu packages)
(gnu packages autotools)
(gnu packages guile)
(gnu packages guile-xyz)
(gnu packages pkg-config)
(gnu packages texinfo))
(guix packages)
((guix licenses) #:prefix license:)
(guix gexp)
(guix git-download)
(guix utils)
(guix build-system copy)
(gnu packages)
(gnu packages autotools)
(gnu packages guile)
(gnu packages guile-xyz)
(gnu packages pkg-config)
(gnu packages texinfo))
(define vcs-file?
(or (git-predicate (current-source-directory))
(const #t)))
(define vcs-file?
(or (git-predicate (current-source-directory))
(const #t)))
(package
(name "guile-guile-docs")
(version "0.1")
(source "./guile-guile-docs-0.1.tar.gz")
(build-system gnu-build-system)
(source (local-file "." "guile-checkout"
#:recursive? #t
#:select? vcs-file?))
(build-system copy-build-system)
(arguments `())
(native-inputs
`(("autoconf" ,autoconf)
("automake" ,automake)
("pkg-config" ,pkg-config)
("texinfo" ,texinfo)))
(inputs `(("guile" ,guile-3.0)))
(inputs (list guile-3.0
haunt))
(propagated-inputs `())
(synopsis "")
(description "")
(home-page "")
(license license:gpl3+))

6
public/index.scm Normal file
View File

@ -0,0 +1,6 @@
'(html
(head
(title "Welcome to Guile Docs"))
(body
(h1 "Welcome to Guile Docs")
(p "This is Guile Docs.")))