diff options
author | Lia Lenckowski <lialenck@protonmail.com> | 2023-10-15 18:42:04 +0200 |
---|---|---|
committer | Lia Lenckowski <lialenck@protonmail.com> | 2023-10-15 18:49:35 +0200 |
commit | a7548f3da3897cd8bb247c784c50d39d642623b9 (patch) | |
tree | 81a73513429e619a4f259947f90e3b13c0e9e815 | |
parent | c575a2d9fe9eab97c6af7d20c577b6ea6a0e72aa (diff) | |
download | fastbangs-a7548f3da3897cd8bb247c784c50d39d642623b9.tar fastbangs-a7548f3da3897cd8bb247c784c50d39d642623b9.tar.bz2 fastbangs-a7548f3da3897cd8bb247c784c50d39d642623b9.tar.zst |
embed resources into executable
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | fastbangs.cabal | 5 | ||||
-rw-r--r-- | makefile | 23 | ||||
-rw-r--r-- | package.yaml | 3 | ||||
-rw-r--r-- | src/Main.hs | 13 |
5 files changed, 26 insertions, 19 deletions
@@ -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 @@ -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 |