mirror of
https://github.com/aelve/guide.git
synced 2024-11-27 10:10:50 +03:00
Move everything to the “/haskell” subpath
This commit is contained in:
parent
59294cc321
commit
eb0e13b94e
38
src/JS.hs
38
src/JS.hs
@ -118,6 +118,8 @@ instance JSParams a => JSFunction (a -> JS) where
|
|||||||
assign :: ToJS x => JS -> x -> JS
|
assign :: ToJS x => JS -> x -> JS
|
||||||
assign v x = JS $ format "{} = {};" (v, toJS x)
|
assign v x = JS $ format "{} = {};" (v, toJS x)
|
||||||
|
|
||||||
|
-- TODO: all links here shouldn't be absolute [absolute-links]
|
||||||
|
|
||||||
replaceWithData :: JSFunction a => a
|
replaceWithData :: JSFunction a => a
|
||||||
replaceWithData =
|
replaceWithData =
|
||||||
makeJSFunction "replaceWithData" ["node"]
|
makeJSFunction "replaceWithData" ["node"]
|
||||||
@ -224,7 +226,7 @@ addCategory :: JSFunction a => a
|
|||||||
addCategory =
|
addCategory =
|
||||||
makeJSFunction "addCategory" ["node", "s"]
|
makeJSFunction "addCategory" ["node", "s"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/add/category", {content: s})
|
$.post("/haskell/add/category", {content: s})
|
||||||
.done(prependData(node));
|
.done(prependData(node));
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -233,7 +235,7 @@ addItem :: JSFunction a => a
|
|||||||
addItem =
|
addItem =
|
||||||
makeJSFunction "addItem" ["node", "catId", "s"]
|
makeJSFunction "addItem" ["node", "catId", "s"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/add/category/"+catId+"/item", {name: s})
|
$.post("/haskell/add/category/"+catId+"/item", {name: s})
|
||||||
.done(appendData(node));
|
.done(appendData(node));
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -246,7 +248,7 @@ submitCategoryTitle :: JSFunction a => a
|
|||||||
submitCategoryTitle =
|
submitCategoryTitle =
|
||||||
makeJSFunction "submitCategoryTitle" ["node", "catId", "s"]
|
makeJSFunction "submitCategoryTitle" ["node", "catId", "s"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/set/category/"+catId+"/title", {content: s})
|
$.post("/haskell/set/category/"+catId+"/title", {content: s})
|
||||||
.done(replaceWithData(node));
|
.done(replaceWithData(node));
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -254,7 +256,7 @@ submitCategoryNotes :: JSFunction a => a
|
|||||||
submitCategoryNotes =
|
submitCategoryNotes =
|
||||||
makeJSFunction "submitCategoryNotes" ["node", "catId", "s"]
|
makeJSFunction "submitCategoryNotes" ["node", "catId", "s"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/set/category/"+catId+"/notes", {content: s})
|
$.post("/haskell/set/category/"+catId+"/notes", {content: s})
|
||||||
.done(replaceWithData(node));
|
.done(replaceWithData(node));
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -262,7 +264,7 @@ submitItemDescription :: JSFunction a => a
|
|||||||
submitItemDescription =
|
submitItemDescription =
|
||||||
makeJSFunction "submitItemDescription" ["node", "itemId", "s"]
|
makeJSFunction "submitItemDescription" ["node", "itemId", "s"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/set/item/"+itemId+"/description", {content: s})
|
$.post("/haskell/set/item/"+itemId+"/description", {content: s})
|
||||||
.done(replaceWithData(node));
|
.done(replaceWithData(node));
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -270,7 +272,7 @@ submitItemEcosystem :: JSFunction a => a
|
|||||||
submitItemEcosystem =
|
submitItemEcosystem =
|
||||||
makeJSFunction "submitItemEcosystem" ["node", "itemId", "s"]
|
makeJSFunction "submitItemEcosystem" ["node", "itemId", "s"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/set/item/"+itemId+"/ecosystem", {content: s})
|
$.post("/haskell/set/item/"+itemId+"/ecosystem", {content: s})
|
||||||
.done(replaceWithData(node));
|
.done(replaceWithData(node));
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -278,7 +280,7 @@ submitItemNotes :: JSFunction a => a
|
|||||||
submitItemNotes =
|
submitItemNotes =
|
||||||
makeJSFunction "submitItemNotes" ["node", "itemId", "s"]
|
makeJSFunction "submitItemNotes" ["node", "itemId", "s"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/set/item/"+itemId+"/notes", {content: s})
|
$.post("/haskell/set/item/"+itemId+"/notes", {content: s})
|
||||||
.done(function (data) {
|
.done(function (data) {
|
||||||
$(node).replaceWith(data);
|
$(node).replaceWith(data);
|
||||||
switchSection(node, "expanded");
|
switchSection(node, "expanded");
|
||||||
@ -293,7 +295,7 @@ addPro :: JSFunction a => a
|
|||||||
addPro =
|
addPro =
|
||||||
makeJSFunction "addPro" ["node", "itemId", "s"]
|
makeJSFunction "addPro" ["node", "itemId", "s"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/add/item/"+itemId+"/pro", {content: s})
|
$.post("/haskell/add/item/"+itemId+"/pro", {content: s})
|
||||||
.done(function (data) {
|
.done(function (data) {
|
||||||
var jData = $(data);
|
var jData = $(data);
|
||||||
jData.appendTo(node);
|
jData.appendTo(node);
|
||||||
@ -306,7 +308,7 @@ addCon :: JSFunction a => a
|
|||||||
addCon =
|
addCon =
|
||||||
makeJSFunction "addCon" ["node", "itemId", "s"]
|
makeJSFunction "addCon" ["node", "itemId", "s"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/add/item/"+itemId+"/con", {content: s})
|
$.post("/haskell/add/item/"+itemId+"/con", {content: s})
|
||||||
.done(function (data) {
|
.done(function (data) {
|
||||||
var jData = $(data);
|
var jData = $(data);
|
||||||
jData.appendTo(node);
|
jData.appendTo(node);
|
||||||
@ -318,7 +320,7 @@ submitTrait :: JSFunction a => a
|
|||||||
submitTrait =
|
submitTrait =
|
||||||
makeJSFunction "submitTrait" ["node", "itemId", "traitId", "s"]
|
makeJSFunction "submitTrait" ["node", "itemId", "traitId", "s"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/set/item/"+itemId+"/trait/"+traitId, {content: s})
|
$.post("/haskell/set/item/"+itemId+"/trait/"+traitId, {content: s})
|
||||||
.done(function (data) {
|
.done(function (data) {
|
||||||
$(node).replaceWith(data);
|
$(node).replaceWith(data);
|
||||||
switchSection(node, "editable");
|
switchSection(node, "editable");
|
||||||
@ -337,13 +339,13 @@ submitItemInfo =
|
|||||||
// it would lose the item's state (e.g. what if the traits were
|
// it would lose the item's state (e.g. what if the traits were
|
||||||
// being edited? etc). So, instead we query colors from the server
|
// being edited? etc). So, instead we query colors from the server
|
||||||
// and change the color of the item's body manually.
|
// and change the color of the item's body manually.
|
||||||
$.post("/set/item/"+itemId+"/info", $(form).serialize())
|
$.post("/haskell/set/item/"+itemId+"/info", $(form).serialize())
|
||||||
.done(function (data) {
|
.done(function (data) {
|
||||||
// Note the order – first we change the color, then we replace
|
// Note the order – first we change the color, then we replace
|
||||||
// the info node. The reason is that otherwise the bodyNode
|
// the info node. The reason is that otherwise the bodyNode
|
||||||
// selector might become invalid (if it depends on the infoNode
|
// selector might become invalid (if it depends on the infoNode
|
||||||
// selector).
|
// selector).
|
||||||
$.get("/render/item/"+itemId+"/colors")
|
$.get("/haskell/render/item/"+itemId+"/colors")
|
||||||
.done(function (colors) {
|
.done(function (colors) {
|
||||||
$(bodyNode).css("background-color", colors.light);
|
$(bodyNode).css("background-color", colors.light);
|
||||||
$(infoNode).replaceWith(data);
|
$(infoNode).replaceWith(data);
|
||||||
@ -355,7 +357,7 @@ moveTraitUp :: JSFunction a => a
|
|||||||
moveTraitUp =
|
moveTraitUp =
|
||||||
makeJSFunction "moveTraitUp" ["itemId", "traitId", "traitNode"]
|
makeJSFunction "moveTraitUp" ["itemId", "traitId", "traitNode"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/move/item/"+itemId+"/trait/"+traitId, {direction: "up"});
|
$.post("/haskell/move/item/"+itemId+"/trait/"+traitId, {direction: "up"});
|
||||||
moveNodeUp(traitNode);
|
moveNodeUp(traitNode);
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -363,7 +365,7 @@ moveTraitDown :: JSFunction a => a
|
|||||||
moveTraitDown =
|
moveTraitDown =
|
||||||
makeJSFunction "moveTraitDown" ["itemId", "traitId", "traitNode"]
|
makeJSFunction "moveTraitDown" ["itemId", "traitId", "traitNode"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/move/item/"+itemId+"/trait/"+traitId, {direction: "down"});
|
$.post("/haskell/move/item/"+itemId+"/trait/"+traitId, {direction: "down"});
|
||||||
moveNodeDown(traitNode);
|
moveNodeDown(traitNode);
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -372,7 +374,7 @@ deleteTrait =
|
|||||||
makeJSFunction "deleteTrait" ["itemId", "traitId", "traitNode"]
|
makeJSFunction "deleteTrait" ["itemId", "traitId", "traitNode"]
|
||||||
[text|
|
[text|
|
||||||
if (confirm("Confirm deletion?")) {
|
if (confirm("Confirm deletion?")) {
|
||||||
$.post("/delete/item/"+itemId+"/trait/"+traitId);
|
$.post("/haskell/delete/item/"+itemId+"/trait/"+traitId);
|
||||||
$(traitNode).remove();
|
$(traitNode).remove();
|
||||||
}
|
}
|
||||||
|]
|
|]
|
||||||
@ -381,7 +383,7 @@ moveItemUp :: JSFunction a => a
|
|||||||
moveItemUp =
|
moveItemUp =
|
||||||
makeJSFunction "moveItemUp" ["itemId", "itemNode"]
|
makeJSFunction "moveItemUp" ["itemId", "itemNode"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/move/item/"+itemId, {direction: "up"});
|
$.post("/haskell/move/item/"+itemId, {direction: "up"});
|
||||||
moveNodeUp(itemNode);
|
moveNodeUp(itemNode);
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -389,7 +391,7 @@ moveItemDown :: JSFunction a => a
|
|||||||
moveItemDown =
|
moveItemDown =
|
||||||
makeJSFunction "moveItemDown" ["itemId", "itemNode"]
|
makeJSFunction "moveItemDown" ["itemId", "itemNode"]
|
||||||
[text|
|
[text|
|
||||||
$.post("/move/item/"+itemId, {direction: "down"});
|
$.post("/haskell/move/item/"+itemId, {direction: "down"});
|
||||||
moveNodeDown(itemNode);
|
moveNodeDown(itemNode);
|
||||||
|]
|
|]
|
||||||
|
|
||||||
@ -398,7 +400,7 @@ deleteItem =
|
|||||||
makeJSFunction "deleteItem" ["itemId", "itemNode"]
|
makeJSFunction "deleteItem" ["itemId", "itemNode"]
|
||||||
[text|
|
[text|
|
||||||
if (confirm("Confirm deletion?")) {
|
if (confirm("Confirm deletion?")) {
|
||||||
$.post("/delete/item/"+itemId);
|
$.post("/haskell/delete/item/"+itemId);
|
||||||
$(itemNode).remove();
|
$(itemNode).remove();
|
||||||
}
|
}
|
||||||
|]
|
|]
|
||||||
|
53
src/Main.hs
53
src/Main.hs
@ -30,7 +30,7 @@ import System.FilePath ((</>))
|
|||||||
import Web.Spock hiding (head, get, text)
|
import Web.Spock hiding (head, get, text)
|
||||||
import qualified Web.Spock as Spock
|
import qualified Web.Spock as Spock
|
||||||
import Web.Spock.Lucid
|
import Web.Spock.Lucid
|
||||||
import qualified Lucid
|
import Lucid
|
||||||
import Network.Wai.Middleware.Static
|
import Network.Wai.Middleware.Static
|
||||||
-- Feeds
|
-- Feeds
|
||||||
import qualified Text.Feed.Types as Feed
|
import qualified Text.Feed.Types as Feed
|
||||||
@ -230,15 +230,6 @@ addMethods = Spock.subcomponent "add" $ do
|
|||||||
|
|
||||||
otherMethods :: SpockM () () DB ()
|
otherMethods :: SpockM () () DB ()
|
||||||
otherMethods = do
|
otherMethods = do
|
||||||
-- Javascript
|
|
||||||
Spock.get "js.js" $ do
|
|
||||||
setHeader "Content-Type" "application/javascript; charset=utf-8"
|
|
||||||
Spock.bytes $ T.encodeUtf8 (fromJS allJSFunctions)
|
|
||||||
-- CSS
|
|
||||||
Spock.get "highlight.css" $ do
|
|
||||||
setHeader "Content-Type" "text/css; charset=utf-8"
|
|
||||||
Spock.bytes $ T.encodeUtf8 (T.pack (styleToCss pygments))
|
|
||||||
|
|
||||||
-- Moving things
|
-- Moving things
|
||||||
Spock.subcomponent "move" $ do
|
Spock.subcomponent "move" $ do
|
||||||
-- Move item
|
-- Move item
|
||||||
@ -260,7 +251,8 @@ otherMethods = do
|
|||||||
dbUpdate (DeleteTrait itemId traitId)
|
dbUpdate (DeleteTrait itemId traitId)
|
||||||
|
|
||||||
-- Feeds
|
-- Feeds
|
||||||
baseUrl <- fromMaybe "" <$> liftIO (lookupEnv "GUIDE_URL")
|
-- TODO: this link shouldn't be absolute [absolute-links]
|
||||||
|
baseUrl <- (</> "haskell") . fromMaybe "/" <$> liftIO (lookupEnv "GUIDE_URL")
|
||||||
Spock.subcomponent "feed" $ do
|
Spock.subcomponent "feed" $ do
|
||||||
-- Feed for items in a category
|
-- Feed for items in a category
|
||||||
Spock.get categoryVar $ \catId -> do
|
Spock.get categoryVar $ \catId -> do
|
||||||
@ -344,18 +336,40 @@ main = do
|
|||||||
runSpock 8080 $ spock config $ do
|
runSpock 8080 $ spock config $ do
|
||||||
middleware (EKG.metrics waiMetrics)
|
middleware (EKG.metrics waiMetrics)
|
||||||
middleware (staticPolicy (addBase "static"))
|
middleware (staticPolicy (addBase "static"))
|
||||||
|
-- Javascript
|
||||||
|
Spock.get "/js.js" $ do
|
||||||
|
setHeader "Content-Type" "application/javascript; charset=utf-8"
|
||||||
|
Spock.bytes $ T.encodeUtf8 (fromJS allJSFunctions)
|
||||||
|
-- CSS
|
||||||
|
Spock.get "/highlight.css" $ do
|
||||||
|
setHeader "Content-Type" "text/css; charset=utf-8"
|
||||||
|
Spock.bytes $ T.encodeUtf8 (T.pack (styleToCss pygments))
|
||||||
|
-- (css.css is a static file and so isn't handled here)
|
||||||
|
|
||||||
-- Main page
|
-- Main page
|
||||||
|
Spock.get root $ lucidIO $ do
|
||||||
|
head_ $ do
|
||||||
|
title_ "Aelve Guide"
|
||||||
|
includeCSS "/css.css"
|
||||||
|
renderTracking
|
||||||
|
body_ $ do
|
||||||
|
h1_ "Aelve Guide"
|
||||||
|
h2_ (a_ [href_ "/haskell"] "Haskell")
|
||||||
|
|
||||||
|
-- Donation page
|
||||||
|
Spock.get "donate" $ do
|
||||||
|
lucidIO $ renderDonate
|
||||||
|
|
||||||
|
-- Haskell
|
||||||
|
Spock.subcomponent "haskell" $ do
|
||||||
Spock.get root $ do
|
Spock.get root $ do
|
||||||
s <- dbQuery GetGlobalState
|
s <- dbQuery GetGlobalState
|
||||||
q <- param "q"
|
q <- param "q"
|
||||||
lucidIO $ renderRoot s q
|
lucidIO $ renderRoot s q
|
||||||
-- Donation page
|
|
||||||
Spock.get "donate" $ do
|
|
||||||
lucidIO $ renderDonate
|
|
||||||
-- Category pages
|
-- Category pages
|
||||||
Spock.get var $ \path -> do
|
Spock.get var $ \path -> do
|
||||||
-- The links look like /generating-feeds-gao238b1 (because it's nice
|
-- The links look like /parsers-gao238b1 (because it's nice when
|
||||||
-- when you can find out where a link leads just by looking at it)
|
-- you can find out where a link leads just by looking at it)
|
||||||
let (_, catId) = T.breakOnEnd "-" path
|
let (_, catId) = T.breakOnEnd "-" path
|
||||||
when (T.null catId) $
|
when (T.null catId) $
|
||||||
Spock.jumpNext
|
Spock.jumpNext
|
||||||
@ -363,10 +377,11 @@ main = do
|
|||||||
case mbCategory of
|
case mbCategory of
|
||||||
Nothing -> Spock.jumpNext
|
Nothing -> Spock.jumpNext
|
||||||
Just category -> do
|
Just category -> do
|
||||||
-- If the slug in the url is old or something (i.e. if it doesn't
|
-- If the slug in the url is old (i.e. if it doesn't match the
|
||||||
-- match the one we would've generated now), let's do a redirect
|
-- one we would've generated now), let's do a redirect
|
||||||
when (categorySlug category /= path) $
|
when (categorySlug category /= path) $
|
||||||
Spock.redirect ("/" <> categorySlug category)
|
-- TODO: this link shouldn't be absolute [absolute-links]
|
||||||
|
Spock.redirect ("/haskell/" <> categorySlug category)
|
||||||
lucidIO $ renderCategoryPage category
|
lucidIO $ renderCategoryPage category
|
||||||
-- The add/set methods return rendered parts of the structure (added
|
-- The add/set methods return rendered parts of the structure (added
|
||||||
-- categories, changed items, etc) so that the Javascript part could
|
-- categories, changed items, etc) so that the Javascript part could
|
||||||
|
@ -254,7 +254,8 @@ renderCategoryTitle category = do
|
|||||||
this = JS.selectId thisId
|
this = JS.selectId thisId
|
||||||
h2_ [id_ thisId] $ do
|
h2_ [id_ thisId] $ do
|
||||||
sectionSpan "normal" [shown, noScriptShown] $ do
|
sectionSpan "normal" [shown, noScriptShown] $ do
|
||||||
a_ [href_ ("/" <> categorySlug category)] $
|
-- TODO: this link shouldn't be absolute [absolute-links]
|
||||||
|
a_ [href_ ("/haskell/" <> categorySlug category)] $
|
||||||
toHtml (category^.title)
|
toHtml (category^.title)
|
||||||
emptySpan "1em"
|
emptySpan "1em"
|
||||||
textButton "edit" $
|
textButton "edit" $
|
||||||
|
Loading…
Reference in New Issue
Block a user