aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Laprade <jesselaprade@gmail.com>2021-04-18 16:47:51 -0400
committerJesse Laprade <jesselaprade@gmail.com>2021-04-20 19:34:44 -0400
commit470bbcc6d32dcf5ee6ffd76196285eb5e08eac6d (patch)
treeb5c38d54cfa6a8efcc7ea2be5c59e8ea530843a3
parent41721ab0f3f56027d1481330d1adf0815b44e363 (diff)
downloadsprout-470bbcc6d32dcf5ee6ffd76196285eb5e08eac6d.tar.gz
sprout-470bbcc6d32dcf5ee6ffd76196285eb5e08eac6d.tar.bz2
sprout-470bbcc6d32dcf5ee6ffd76196285eb5e08eac6d.zip
Replaced configuration system with built-in Scheme procedures!
- Replaced yaml config with a good ol' s-expression config! - Removed yaml dependency - Changed make file so the `install` command will work both on Linux and macs - Updated readme according to new changes - Removed old todo (Thanks again Zach! I hope you dont mind me going full-on scheme with the new s-expression config file!)
-rw-r--r--Makefile12
-rw-r--r--README.md20
-rw-r--r--sprout.rkt76
3 files changed, 49 insertions, 59 deletions
diff --git a/Makefile b/Makefile
index c506556..accab26 100644
--- a/Makefile
+++ b/Makefile
@@ -2,13 +2,10 @@ PROGRAM = sprout
DESTDIR ?= /usr/local/bin
LOCALDIR = ~/.local/bin
-.PHONY: install-mac
-install-mac: build
- install -m755 ./$(PROGRAM) $(DESTDIR)/$(PROGRAM)
-
.PHONY: install
install: build
- install -Dm755 ./$(PROGRAM) -D $(DESTDIR)/$(PROGRAM)
+ chmod ugo+x ./$(PROGRAM)
+ mv ./$(PROGRAM) $(DESTDIR)/$(PROGRAM)
.PHONY: uninstall
uninstall: $(DESTDIR)/$(PROGRAM)
@@ -17,9 +14,6 @@ uninstall: $(DESTDIR)/$(PROGRAM)
build: $(PROGRAM).rkt
raco exe -o ./$(PROGRAM) $(PROGRAM).rkt
-deps:
- raco pkg install yaml
-
.PHONY: clean
-clean:
+clean: ./$(PROGRAM)
rm ./$(PROGRAM)
diff --git a/README.md b/README.md
index 4664401..620f46b 100644
--- a/README.md
+++ b/README.md
@@ -75,11 +75,10 @@ follow the steps below to install sprout on your local machine:
1. run `git clone https://git.m455.casa/m455/sprout`
2. run `cd sprout`
-3. run `make deps`
-4. run `make install` as root
-5. run `sprout`
-6. type `y` when prompted
-7. type `s` to change your settings
+3. run `make install` as root
+4. run `sprout`
+5. type `y` when prompted
+6. type `s` to change your settings
### prepare your server
@@ -110,13 +109,12 @@ follow the steps below on tilde.town:
1. run `mkdir ~/public_html/weed`
2. run `git clone https://git.m455.casa/m455/sprout`
3. run `cd sprout`
-4. run `make deps`
-5. run `make install DESTDIR=~/.local/bin
-6. run `sprout`
-7. type `y` when prompted
-8. type `s` to change your settings
+4. run `mkdir -p ~/.local/bin`
+4. run `make install DESTDIR=~/.local/bin
+5. run `sprout`
+6. type `y` when prompted
+7. type `s` to change your settings
## todos
-* DONE! (Thanks for telling me about Racket's yaml library and contributing, Zach!): figure out how the hell to make a config file
* implement pagination
diff --git a/sprout.rkt b/sprout.rkt
index 3cb145f..83a7929 100644
--- a/sprout.rkt
+++ b/sprout.rkt
@@ -5,8 +5,7 @@
racket/string
racket/file
racket/list
- racket/match
- yaml)
+ racket/match)
(define dir-weed (string-append (path->string (find-system-path 'home-dir)) ".weed/"))
(define dir-posts (string-append dir-weed "posts/"))
@@ -16,33 +15,29 @@
(define rss-file "weed.rss")
(define rss-file-build (string-append dir-build rss-file))
-(define yaml-file "config.yaml")
-(define yaml-file-location (string-append dir-weed yaml-file))
+(define config-file "config")
+(define config-file-path (string-append dir-weed config-file))
-(define yaml-file-contents
+(define config-file-contents
#<<string-block
-###################################
-# This is the config for your weed.
-# Change to your own values!
-###################################
-#
-#
-# becomes the RSS title
-title: "My Cool Weed"
-
-# becomes the RSS description
-description: "My feels and good thoughts and such."
-
-# the web directory of the rss feed
-# note: make sure you include the trailing slash! :O
-url-base: "https://example.site/weed/"
-
-# we use rsync to publish weed.rss to this path, so it can be a local or remote directory
-# examples:
-# local example: "~/path/to/dir/"
-# remote example "user@host:/path/to/dir/"
-# note: make sure you include the trailing slash! :O
-output-path: "~/sites/my-example-site/www/weed/"
+;; This is the config file for your weed.
+;; Change the values here to your own values
+
+((title "My Cool Weed")
+ (description "My feels and good thoughts and such")
+
+ ;; This is the web directory of your weed file
+ ;; Note: Make sure you include the trailing slash :o
+ (url-base "https://example.site/weed/")
+
+ ;; This is where your feed will be published using rsync.
+ ;; This could be a local path or a remote path.
+ ;;
+ ;; Examples:
+ ;; Local example: "~/public_html/weed/"
+ ;; Remote example: "user@host:/var/www/weed/"
+ ;; Note: Make sure you include the trailing slash :o
+ (output-path "~/sites/my-example-site/www/weed/"))
string-block
)
@@ -78,6 +73,11 @@ string-block
string-block
)
+(define (config-ref key)
+ (with-input-from-file
+ config-file-path
+ (lambda () (cadr (assq key (read))))))
+
(define (rss-remove-illegal-characters str)
(string-replace str "]]>" ""))
@@ -93,7 +93,7 @@ string-block
(system (format str ...)))
(define (press-enter)
- (displayln "press enter to continue...")
+ (display "press enter to continue...")
(read-line))
(define (directory-create str)
@@ -120,9 +120,6 @@ string-block
env-visual
(get-editor-fallback))))
-(define (yaml-ref key)
- (hash-ref (file->yaml yaml-file-location) key))
-
(define (string-cleanup str)
((compose
(lambda (x) (string-replace x #px"\t+" " "))
@@ -195,7 +192,7 @@ string-block
(define (publish)
(let* ([posts (directory-list dir-posts)]
- [remote-location (string-append (yaml-ref "output-path") rss-file)])
+ [remote-location (string-append (config-ref 'output-path) rss-file)])
(if (> (length posts) 0)
(begin (clear-screen)
(system-format "rsync -av --delete ~a ~a" rss-file-build remote-location)
@@ -211,10 +208,10 @@ string-block
[posts-full-paths (map (lambda (x) (string-append dir-posts x))
posts-as-strings)]
[header (format rss-header
- (yaml-ref "title")
- (yaml-ref "url-base")
- (yaml-ref "description")
- (string-append (yaml-ref "url-base") rss-file))])
+ (config-ref 'title)
+ (config-ref 'url-base)
+ (config-ref 'description)
+ (string-append (config-ref 'url-base) rss-file))])
;; write header to file
(display-to-file header rss-file-build #:exists 'truncate)
;; write items to file
@@ -256,7 +253,7 @@ string-block
(press-enter))))
(define (settings)
- (system-format "~a ~a" (get-editor) yaml-file-location))
+ (system-format "~a ~a" (get-editor) config-file-path))
(define (edit-post number)
(if (and (> (length (directory-list dir-posts)) 0)
@@ -335,7 +332,8 @@ string-block
(define (setup)
(for ([i dirs])
(directory-create i))
- (display-to-file yaml-file-contents yaml-file-location #:exists 'truncate)
+ (display-to-file config-file-contents config-file-path #:exists 'truncate)
+ (displayln (format "created ~a" config-file-path))
(displayln "finished setup!")
(press-enter)
(draw-interface))
@@ -353,7 +351,7 @@ string-block
(define (main)
(if (and (andmap directory-exists? dirs)
- (file-exists? yaml-file-location))
+ (file-exists? config-file-path))
(draw-interface)
(prompt-to-setup)))