aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--fastbangs.cabal5
-rw-r--r--makefile23
-rw-r--r--package.yaml3
-rw-r--r--src/Main.hs13
5 files changed, 26 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index 1ab3e8d..17fbd50 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
.stack-work
/deploy
+/build
frontend/fuzzysort.js
diff --git a/fastbangs.cabal b/fastbangs.cabal
index f8bbd63..6b6e5a9 100644
--- a/fastbangs.cabal
+++ b/fastbangs.cabal
@@ -1,11 +1,11 @@
cabal-version: 1.12
--- This file has been generated from package.yaml by hpack version 0.35.2.
+-- This file has been generated from package.yaml by hpack version 0.36.0.
--
-- see: https://github.com/sol/hpack
name: fastbangs
-version: 0.1.0.0
+version: 0.1.0.1
category: Web
homepage: https://codeberg.org/lialenck/fastbangs
author: Lia Lenckowski
@@ -35,6 +35,7 @@ executable fastbangs
, bytestring
, containers
, cryptonite
+ , file-embed
, ghc-prim
, http-conduit
, memory
diff --git a/makefile b/makefile
index b2e49af..779b17c 100644
--- a/makefile
+++ b/makefile
@@ -1,8 +1,8 @@
ESFLAGS = --target=esnext --format=esm
-deploy-dir: deploy deploy/bundle.js deploy/style.css deploy/index.html deploy/fastbangs deploy/fastbangs.yaml
+deploy-dir: deploy deploy/fastbangs deploy/fastbangs.yaml
-.PHONY: watch-script watch-style clean deploy-dir
+.PHONY: watch-script watch-style clean deploy-dir build-dir
watch-script: frontend/fuzzysort.js
esbuild frontend/main.ts --bundle --outfile=deploy/bundle.js $(ESFLAGS) --watch
watch-style:
@@ -10,26 +10,29 @@ watch-style:
clean:
stack clean --full
- rm -f deploy/{bundle.js,index.html,fastbangs,style.css}
rm -f deploy.zip
rm -f frontend/fuzzysort.js
+ rm -rf build
# This leaves the deploy directory, which is intentional, as it may contain
# user data
+build-dir:
+ mkdir -p build
+build/index.html: frontend/index.html build-dir
+ cp $< $@
+build/bundle.js: $(shell find frontend -name '*.ts') frontend/fuzzysort.js build-dir
+ esbuild frontend/main.ts --bundle --outfile=build/bundle.js $(ESFLAGS)
+build/style.css: frontend/style.sass build-dir
+ sassc $< $@
+
deploy.zip: deploy-dir
zip deploy.zip -r deploy
deploy:
mkdir -p deploy
-deploy/index.html: frontend/index.html
- cp $< $@
deploy/fastbangs.yaml: fastbangs.yaml
cp --no-clobber $< $@; true
-deploy/fastbangs: $(shell find src -name '*.hs')
+deploy/fastbangs: $(shell find src -name '*.hs') build/bundle.js build/index.html build/style.css
stack install --local-bin-path deploy
-deploy/bundle.js: $(shell find frontend -name '*.ts') frontend/fuzzysort.js
- esbuild frontend/main.ts --bundle --outfile=deploy/bundle.js $(ESFLAGS)
-deploy/style.css: frontend/style.sass
- sassc $< $@
frontend/fuzzysort.js:
curl -s 'https://cdn.jsdelivr.net/npm/fuzzysort@2.0.4/fuzzysort.min.js' -o $@
diff --git a/package.yaml b/package.yaml
index 5657107..2b13bf1 100644
--- a/package.yaml
+++ b/package.yaml
@@ -1,5 +1,5 @@
name: fastbangs
-version: 0.1.0.0
+version: 0.1.0.1
#synopsis:
#description:
homepage: https://codeberg.org/lialenck/fastbangs
@@ -33,6 +33,7 @@ dependencies:
- process
- resource-pool
- unliftio-core
+- file-embed
ghc-options:
- -Wall
diff --git a/src/Main.hs b/src/Main.hs
index d69ced6..03709d4 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -11,6 +11,7 @@ import Control.Monad.Trans.Resource (runResourceT)
import Control.Monad (when, unless)
import Database.Persist.Sqlite
import Data.Bool (bool)
+import Data.FileEmbed (embedFile)
import Data.Function ((&))
import Data.Pool (Pool)
import Network.Wai.Handler.Warp hiding (getPort, getHost)
@@ -53,20 +54,20 @@ instance YesodPersist Search where
runDB action = getYesod >>= runSqlPool action . sqlPool
-getHomeR :: Handler ()
+getHomeR :: Handler TypedContent
getHomeR = do
cacheSeconds $ 60 * 60 * 24 * 7
- sendFile typeHtml "index.html"
+ return $ TypedContent typeHtml $ toContent ($(embedFile "build/index.html"))
-getBundleR :: Handler ()
+getBundleR :: Handler TypedContent
getBundleR = do
cacheSeconds $ 60 * 60 * 24 * 7
- sendFile typeJavascript "bundle.js"
+ return $ TypedContent typeJavascript $ toContent ($(embedFile "build/bundle.js"))
-getStyleR :: Handler ()
+getStyleR :: Handler TypedContent
getStyleR = do
cacheSeconds $ 60 * 60 * 24 * 7
- sendFile typeCss "style.css"
+ return $ TypedContent typeCss $ toContent ($(embedFile "build/style.css"))
getBangsR :: Handler TypedContent
getBangsR = do