Skip to content

Commit

Permalink
Update tailwind for liveserver (#503)
Browse files Browse the repository at this point in the history
This change makes the liveserver works with the latest tailwind version,
similarly to what the site export produce.
  • Loading branch information
TristanCacqueray authored Jan 23, 2024
1 parent b38035c commit 36d27aa
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 22 deletions.
1 change: 1 addition & 0 deletions emanote/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- KaTeX support ([\#489](https://github.com/srid/emanote/pull/489))
- Lua filters: filter paths will now be looked up in all layers now.
- **BACKWARDS INCOMPTABILE**: `feed.siteUrl` is now `page.siteUrl`
- Live server now uses Tailwind 3 ([\#503](https://github.com/srid/emanote/pull/503))
- Enable auto identifier for org files ([\#502](https://github.com/srid/emanote/pull/502))
- Bug fixes:
- Emanote no longer crashes when run on an empty directory ([\#487](https://github.com/srid/emanote/issues/487))
Expand Down

This file was deleted.

7 changes: 2 additions & 5 deletions emanote/default/_emanote-live-server/tailwind/README.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
Files in this directory are excluded from the static site, as they are used only the live server.

To upgrade the tailwind CDN css, download it from a URL like
https://unpkg.com/tailwindcss@2.2.2/dist/tailwind.min.css and position it in the
appropriate directory, before updating the path in `LiveServerFiles.hs`.

Unfortunately there is no CDN for 3.x: https://github.com/tailwindlabs/tailwindcss/issues/6355
To upgrade the tailwind CDN js:
curl -L https://cdn.tailwindcss.com > tailwind.min.js
63 changes: 63 additions & 0 deletions emanote/default/_emanote-live-server/tailwind/tailwind.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion emanote/default/index.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ template:
enable: false
# Class to apply for uptree's nodes
nodeClass: text-gray-900 hover:bg-${theme}-500 hover:text-white cursor-pointer
# List of available colors: https://v2.tailwindcss.com/docs/customizing-colors#default-color-palette
# List of available colors: https://tailwindcss.com/docs/customizing-colors#default-color-palette
theme: blue
# Value of the <base> tag.
baseUrl: /
Expand Down
4 changes: 2 additions & 2 deletions emanote/emanote.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 2.4
name: emanote
version: 1.3.9.0
version: 1.3.10.0
license: AGPL-3.0-only
copyright: 2022 Sridhar Ratnakumar
maintainer: srid@srid.ca
Expand All @@ -20,7 +20,7 @@ extra-source-files:

data-dir: default
data-files:
_emanote-live-server/**/*.css
_emanote-live-server/**/*.js
_emanote-static/**/*.ttf
_emanote-static/*.css
_emanote-static/*.svg
Expand Down
2 changes: 1 addition & 1 deletion emanote/src/Emanote/Route/SiteRoute/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ emanoteGeneratableRoutes model =
staticRoutes =
let includeFile f =
not (LiveServerFile.isLiveServerFile f)
|| (f == LiveServerFile.tailwindFullCssPath && not (model ^. M.modelCompileTailwind))
|| (f == LiveServerFile.tailwindFullJsPath && not (model ^. M.modelCompileTailwind))
in model
^. M.modelStaticFiles
& Ix.toList
Expand Down
9 changes: 4 additions & 5 deletions emanote/src/Emanote/View/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,10 @@ commonSplices withCtx model meta routeTitle = do
let localCdnUrl =
SR.siteRouteUrl model
$ SR.staticFileSiteRoute
$ LiveServerFiles.tailwindCssFile model
H.link
! A.href (H.toValue localCdnUrl)
! A.rel "stylesheet"
! A.type_ "text/css"
$ LiveServerFiles.tailwindJsFile model
H.script
! A.src (H.toValue localCdnUrl)
$ mempty

renderModelTemplate :: Model -> Tmpl.TemplateName -> H.Splices (HI.Splice Identity) -> LByteString
renderModelTemplate model templateName =
Expand Down
14 changes: 7 additions & 7 deletions emanote/src/Emanote/View/LiveServerFiles.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Emanote.View.LiveServerFiles (
isLiveServerFile,
tailwindFullCssPath,
tailwindCssFile,
tailwindFullJsPath,
tailwindJsFile,
) where

import Data.Text qualified as T
Expand All @@ -14,13 +14,13 @@ import Relude
baseDir :: FilePath
baseDir = "_emanote-live-server"

tailwindFullCssPath :: FilePath
tailwindFullCssPath = baseDir <> "/tailwind/2.2.2/tailwind.min.css"
tailwindFullJsPath :: FilePath
tailwindFullJsPath = baseDir <> "/tailwind/tailwind.min.js"

isLiveServerFile :: FilePath -> Bool
isLiveServerFile (toText -> fp) =
toText baseDir `T.isPrefixOf` fp

tailwindCssFile :: M.Model -> StaticFile
tailwindCssFile model =
fromMaybe (error "model not ready?") $ M.modelLookupStaticFile tailwindFullCssPath model
tailwindJsFile :: M.Model -> StaticFile
tailwindJsFile model =
fromMaybe (error "model not ready?") $ M.modelLookupStaticFile tailwindFullJsPath model

0 comments on commit 36d27aa

Please sign in to comment.