aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Laprade <jesselaprade@gmail.com>2021-04-17 11:21:20 -0400
committerJesse Laprade <jesselaprade@gmail.com>2021-04-17 11:21:20 -0400
commitbe71ea4f64b57d2dfcf1b603895c0fefbea2eec5 (patch)
treefb68810af284231e07d2f532e2d5bb6921cdc06f
parente38e71bd98ba30cf38ee92b397cb9735fe8d14ee (diff)
downloadsprout-be71ea4f64b57d2dfcf1b603895c0fefbea2eec5.tar.gz
sprout-be71ea4f64b57d2dfcf1b603895c0fefbea2eec5.tar.bz2
sprout-be71ea4f64b57d2dfcf1b603895c0fefbea2eec5.zip
Added config file generation during setup!
- Worked off Zach's changes (thanks!!!) - Instead of having to configure before using the Makefile, you can now configure while the program is running!! - Fixed some bugs in the Makefile - Removed install-local in favour of just changing the DESTDIR value
-rw-r--r--Makefile19
-rw-r--r--README.md34
-rw-r--r--config.yaml16
-rw-r--r--sprout.rkt88
4 files changed, 74 insertions, 83 deletions
diff --git a/Makefile b/Makefile
index 197128f..062b588 100644
--- a/Makefile
+++ b/Makefile
@@ -2,28 +2,21 @@ PROGRAM = sprout
DESTDIR ?= /usr/local/bin
LOCALDIR = ~/.local/bin
-compile: $(PROGRAM).rkt
- raco exe -o ./$(PROGRAM) $(PROGRAM).rkt
-
.PHONY: install-mac
-install-mac: compile
+install-mac: build
install -m755 ./$(PROGRAM) $(DESTDIR)/$(PROGRAM)
.PHONY: install
-install: compile
+install: build
install -Dm755 ./$(PROGRAM) -D $(DESTDIR)/$(PROGRAM)
-.PHONY: install-local
-install-local: compile
- install -Dm755 ./$(PROGRAM) -D $(LOCALDIR)/$(PROGRAM)
-
.PHONY: uninstall
-uninstall: $(LOCALDIR)/$(PROGRAM)
+uninstall: $(DESTDIR)/$(PROGRAM)
rm $(DESTDIR)/$(PROGRAM)
-.PHONY: uninstall-local
-uninstall-local: $(LOCALDIR)/$(PROGRAM)
- rm $(LOCALDIR)/$(PROGRAM)
+build: $(PROGRAM).rkt
+ raco pkg install yaml
+ raco exe -o ./$(PROGRAM) $(PROGRAM).rkt
.PHONY: clean
clean:
diff --git a/README.md b/README.md
index 42b8d2b..959f58b 100644
--- a/README.md
+++ b/README.md
@@ -75,14 +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. change the values of the following definitions in `src/sprout.rkt`:
- * `rss-title`
- * `rss-description`
- * `rss-url-base`
- * `rss-remote-location`
-4. run `sudo make install`
-5. run `sprout`
-6. type `y` when prompted.
+3. run `make install` as root
+4. run `sprout`
+5. type `y` when prompted
+6. type `s` to change your settings
### prepare your server
@@ -108,25 +104,17 @@ follow the steps below to prepare your server:
## for tilde.town users!
-follow the steps below on your local machine:
-
-1. run `git clone https://git.m455.casa/m455/sprout`
-2. run `cd sprout`
-3. change the values of the following definitions in `src/sprout.rkt`:
- * `rss-title`
- * `rss-description`
- * change the value of `rss-url-base` to `http://tilde.town/~yourusername/`
- * change the value of `rss-remote-location` to `yourusername@tilde.town:~/public_html/weed/`
-4. run `make install-local`
-5. run `sprout`
-6. type `y` when prompted.
-
follow the steps below on tilde.town:
1. run `mkdir ~/public_html/weed`
-2. ... that's all!
+2. run `git clone https://git.m455.casa/m455/sprout`
+3. run `cd sprout`
+4. run `make install DESTDIR=~/.local/bin
+5. run `sprout`
+6. type `y` when prompted
+7. type `s` to change your settings
## todos
-* figure out how the hell to make a config file
+* 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/config.yaml b/config.yaml
deleted file mode 100644
index f890423..0000000
--- a/config.yaml
+++ /dev/null
@@ -1,16 +0,0 @@
-###################################
-# 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 location of the rss feed, e.g. m455.casa/weed
-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
-# local example: "~/path/to/dir"
-# remote example "user@host:/path/to/dir"
-output-path: "~/sites/my-example-site/www/weed"
diff --git a/sprout.rkt b/sprout.rkt
index bde06e4..2caa2ea 100644
--- a/sprout.rkt
+++ b/sprout.rkt
@@ -2,12 +2,10 @@
(require racket/port
racket/system
- racket/dict
racket/string
racket/file
racket/list
racket/match
- racket/serialize
yaml)
(define dir-weed (string-append (path->string (find-system-path 'home-dir)) ".weed/"))
@@ -15,23 +13,40 @@
(define dir-build (string-append dir-weed "build/"))
(define dirs (list dir-weed dir-posts dir-build))
-(define config (file->yaml "config.yaml"))
-(define rss-title (dict-ref config "title"))
-(define rss-description (dict-ref config "description"))
-(define rss-url-base (dict-ref config "url-base"))
-(define rss-remote-location (dict-ref config "output-path"))
(define rss-file "weed.rss")
-(define rss-file-url (string-append rss-url-base rss-file))
(define rss-file-build (string-append dir-build rss-file))
-;; RSS shenanigans
-;; =========================================
+(define yaml-file "config.yaml")
+(define yaml-file-location (string-append dir-weed yaml-file))
-(define (rss-remove-illegal-characters str)
- (string-replace str "]]>" ""))
+(define yaml-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/"
+string-block
+)
(define rss-header
- (format
#<<string-block
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
@@ -42,11 +57,7 @@
<atom:link href="~a" rel="self" type="application/rss+xml" />
string-block
-rss-title
-rss-url-base
-rss-description
-rss-file-url
-))
+)
(define rss-item
#<<string-block
@@ -66,8 +77,10 @@ string-block
</rss>
string-block
)
-;; utils
-;; =========================================
+
+(define (rss-remove-illegal-characters str)
+ (string-replace str "]]>" ""))
+
(define (clear-screen)
(let ([clear-screen "\e[2J"]
[reset-cursor "\e[1;1H"])
@@ -169,11 +182,6 @@ string-block
(lambda (x) (string-replace x "\n\n" "</p><p>"))
rss-remove-illegal-characters)
(file->string filename)))
- ;; old
- ;((compose
- ; (lambda (x) (string-replace x #px"\n$" ""))
- ; rss-remove-illegal-characters)
- ; (file->string filename)))
;; commands
;; =========================================
@@ -183,10 +191,12 @@ string-block
(exit 0))
(define (publish)
- (let ([posts (directory-list dir-posts)])
+ (let* ([posts (directory-list dir-posts)]
+ [config (file->yaml yaml-file-location)]
+ [remote-location (string-append (hash-ref config "output-path") rss-file)])
(if (> (length posts) 0)
(begin (clear-screen)
- (system-format "rsync -av --delete ~a ~a" rss-file-build rss-remote-location)
+ (system-format "rsync -av --delete ~a ~a" rss-file-build remote-location)
(displayln "weed published!")
(press-enter))
(begin (displayln "woops! no posts to publish!")
@@ -197,9 +207,16 @@ string-block
(if (> (length posts) 0)
(let* ([posts-as-strings (map path->string posts)]
[posts-full-paths (map (lambda (x) (string-append dir-posts x))
- posts-as-strings)])
+ posts-as-strings)]
+ [config (file->yaml yaml-file-location)]
+ [config-ref (lambda (arg) (hash-ref config arg))]
+ [header (format rss-header
+ (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 rss-header rss-file-build #:exists 'truncate)
+ (display-to-file header rss-file-build #:exists 'truncate)
;; write items to file
(for ([file posts-full-paths])
(let* ([title (make-title file)]
@@ -238,6 +255,9 @@ string-block
(begin (displayln "woops!")
(press-enter))))
+(define (settings)
+ (system-format "~a ~a" (get-editor) yaml-file-location))
+
(define (edit-post number)
(if (and (> (length (directory-list dir-posts)) 0)
(>= number 0)
@@ -269,7 +289,8 @@ string-block
"e <n>: edit <nth> post"
"d <n>: delete <nth> post"
"b: build an rss feed from your posts"
- "p: publish your posts")])
+ "p: publish your posts"
+ "s: change settings")])
(displayln line))
(newline)
(press-enter))
@@ -291,6 +312,7 @@ string-block
(match (string-split input)
[(list "e" (app string->number (? number? x))) (edit-post x)]
[(list "d" (app string->number (? number? x))) (delete-post x)]
+ [(list "s") (settings)]
[(list "h") (draw-help)]
[(list "c") (create-post)]
[(list "b") (build-rss)]
@@ -313,6 +335,9 @@ string-block
(define (setup)
(for ([i dirs])
(directory-create i))
+ (display-to-file yaml-file-contents yaml-file-location #:exists 'truncate)
+ (displayln "finished setup!")
+ (press-enter)
(draw-interface))
(define (prompt-to-setup)
@@ -327,7 +352,8 @@ string-block
(displayln "cancelled setup.")))))
(define (main)
- (if (andmap directory-exists? dirs)
+ (if (and (andmap directory-exists? dirs)
+ (file-exists? yaml-file-location))
(draw-interface)
(prompt-to-setup)))