diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-10-25 22:02:51 +0200 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-10-25 22:02:51 +0200 |
commit | 3da1b7f818787e99b6cf1c363521ef45c033f5e1 (patch) | |
tree | cd062dbcb6d033ecd6193dcefe4284859b46bafe | |
parent | work (diff) | |
download | vimwiki-scripts-3da1b7f818787e99b6cf1c363521ef45c033f5e1.tar.gz vimwiki-scripts-3da1b7f818787e99b6cf1c363521ef45c033f5e1.tar.xz |
work
-rw-r--r-- | hs/Html.hs | 98 | ||||
-rw-r--r-- | hs/main.hs | 9 | ||||
-rw-r--r-- | hs/style2.css | 123 |
3 files changed, 210 insertions, 20 deletions
@@ -7,6 +7,7 @@ module Html ( main ) where +import System.Environment (getArgs) import System.FilePath ( joinPath , takeDirectory @@ -17,6 +18,7 @@ import System.FilePath , dropExtension , takeBaseName ) + import Text.Pandoc ( PandocMonad , PandocIO @@ -51,8 +53,8 @@ import Text.Pandoc.Writers.Shared import Data.Text (Text, unpack, pack) import Data.Text.IO qualified as T import Data.Text.Lazy (toStrict) -import Network.URI (parseURI, uriPath, uriScheme, URI) -import Data.Maybe (listToMaybe) +import Network.URI (parseURI, uriPath, uriScheme, uriFragment, uriQuery, URI) +import Data.Maybe (listToMaybe, fromMaybe) import Control.Monad.IO.Class (liftIO) @@ -85,6 +87,7 @@ import Links import Data.Map qualified as M import Data.Set (Set) import Data.Set qualified as S +import Data.String (IsString) (&) = flip ($) @@ -107,13 +110,49 @@ vimwikiToHTML txt = do return $ toStrict . renderHtml $ html -} +data Configuration = Configuration + { inputDir :: FilePath + , outputDir :: FilePath + -- Are we in a subdirectory from the web root? + -- /tmp/wiki + , webPath :: String + -- http://localhost:8090/ + , mu4eURL :: String + -- http://wiki.gandalf.adrift.space/search + , xapianOmega :: String + } + type UrlRewriter = [Inline] -> URI -> ([Inline], Text) mailRewriter :: UrlRewriter -mailRewriter body uri = (body, pack $ "http://localhost:8090/?id=" <> (uriPath uri)) +mailRewriter body uri = (body, pack $ "http://localhost:8090/" <> "?id=" <> (uriPath uri)) + +-- Comparison of online man pages: +-- https://gist.github.com/rixx/6cb5fa38f694009ad0bd50c275bb61f2 + +archMan :: (Semigroup a, IsString a) => a -> Maybe a -> Maybe a -> a +archMan page section' language' + = "https://man.archlinux.org/man/" <> page <> f section' <> f language' + where f = fromMaybe "" . fmap ("." <>) + +mannedMan :: (Semigroup a, IsString a) => a -> Maybe a -> Maybe a -> a +mannedMan page section' language' + = "https://manned.org/man" <> f language' <> "/" <> page <> f section' + where f = fromMaybe "" . fmap ("." <>) + +manRewriter :: UrlRewriter +manRewriter _ uri + = ([Str $ path <> "(" <> (fromMaybe "?" section') <> ")"] + , mannedMan path section' language') + where path :: Text + path = pack $ uriPath uri + section' = pack . tail <$> nullToMaybe (uriFragment uri) + language' = pack . tail <$> nullToMaybe (uriQuery uri) urlRewrites :: M.Map String UrlRewriter -urlRewrites = M.fromList [("mail", mailRewriter)] +urlRewrites = M.fromList [ ("mail", mailRewriter) + , ("man", manRewriter) + ] -- -- TODO don't do this for inter-page links @@ -230,18 +269,26 @@ htmlWrap title parts backlinks toc main = docTypeHtml $ do H.meta ! charset "utf-8" H.meta ! name "generator" ! content "pandoc" H.meta ! name "viewport" ! content "width=device-width, initial-scale=1.0, user-scalable=yes" - H.link ! rel "stylesheet" ! href "/tmp/wiki/style.css" + H.link ! rel "stylesheet" ! (href $ "/tmp/wiki" <> "/style.css") H.title $ H.string $ title <> " — Vimwiki" H.body $ do - -- H.header {} + H.header $ do + H.nav ! A.id "breadcrumb" $ do + let bc = (buildBreadcrumbs . breadcrumbLinks $ init parts) + -- TODO replace /tmp/wiki with wiki-base + let all = mconcat [ [ H.a ! href ("/tmp/wiki" <> "/index.html") $ "⌂" ] + , tail bc + , [ H.span $ H.string . takeBaseName . last $ parts ] ] + mconcat $ intersperse (H.string "»") all + H.nav ! A.id "search" $ do + H.form ! A.method "GET" + ! A.action "http://xapian.gandalf.adrift.space" + $ do + H.input ! A.type_ "search" ! A.name "P" ! A.placeholder "Sök..." + H.input ! A.type_ "submit" ! A.value "Sök" H.nav ! A.id "TOC" ! role "doc-toc" $ do H.h2 ! A.id "toc-title" $ "Table of Contents" toc - H.nav ! A.id "breadcrumb" $ do - let bc = (buildBreadcrumbs . breadcrumbLinks $ init parts) - -- TODO replace /tmp/wiki with wiki-base - let all = [ H.a ! href "/tmp/wiki/index.html" $ "⌂" ] ++ tail bc ++ [ H.span $ H.string . takeBaseName . last $ parts ] - mconcat $ intersperse (H.string "»") all H.main $ main H.footer $ do backlinks @@ -269,11 +316,11 @@ nullToMaybe m | otherwise = Just m -handlePart :: M.Map Text (Set FilePath) -> FilePath -> [FilePath] -> PandocIO () -handlePart backlinks wiki_root parts = do +handlePart :: FilePath -> M.Map Text (Set FilePath) -> FilePath -> [FilePath] -> PandocIO () +handlePart outdir backlinks wiki_root parts = do let item_path = joinPath parts let inTarget = wiki_root </> item_path - let outTarget = "/tmp/wiki" </> item_path -<.> "html" + let outTarget = outdir </> item_path -<.> "html" liftIO $ mkdirP . takeDirectory $ outTarget text <- liftIO $ T.readFile inTarget @@ -305,17 +352,28 @@ handlePart backlinks wiki_root parts = do main = do - let wiki_root = "/home/hugo/wiki/private" + args <- getArgs + (indir, outdir) <- case args of + [indir, outdir] -> return (indir, outdir) + _ -> error "Usage: vimwiki <indir> <outdir>" + -- let wiki_root = "/home/hugo/wiki/private" -- wiki_files :: [(FileStatus, [FilePath])] - wiki_files <- filter (uncurry isWikiFile) <$> fileTree [ wiki_root ] + wiki_files <- filter (uncurry isWikiFile) <$> fileTree [ indir ] -- TODO copy remaining files verbatim - -- st <- getFileStatus $ wiki_root </> "Vimwiki.wiki" - -- wiki_files <- return $ [(st, snoc [ wiki_root ] "Vimwiki.wiki")] + -- st <- getFileStatus $ indir </> "Vimwiki.wiki" + -- wiki_files <- return $ [(st, snoc [ indir ] "Vimwiki.wiki")] let relative_paths = tail . snd <$> wiki_files + let conf = Configuration { inputDir = indir + , outputDir = outdir + , webPath = "/tmp/wiki" + , mu4eURL = "http://localhost:8090" + , xapianOmega = "http://wiki.gandalf.adrift.space/search" + } + -- What each page links to -- forwardLinks :: [(FilePath, [String])] - forwardLinks <- runIOorExplode $ mapM (findLinks wiki_root) relative_paths + forwardLinks <- runIOorExplode $ mapM (findLinks indir) relative_paths let backlinks = M.unions $ uncurry buildBacklinkSet <$> forwardLinks --print backlinks @@ -326,5 +384,5 @@ main = do Nothing -> return () Just l -> setTranslations l - mapM_ (handlePart backlinks wiki_root) relative_paths + mapM_ (handlePart outdir backlinks indir) relative_paths -- mapM_ (putStrLn . show) wiki_files @@ -17,3 +17,12 @@ main = Html.main -- Special url types -- - wn.public: -- - mail: +-- +-- +-- För handlingar: +-- - Output forms +-- - LaTeX +-- - Plain Text +-- - HTML Pages +-- - Roxen Pages +-- - Mail with attachements diff --git a/hs/style2.css b/hs/style2.css new file mode 100644 index 0000000..42bfb02 --- /dev/null +++ b/hs/style2.css @@ -0,0 +1,123 @@ +body { + display: grid; + /* grid-template-columns: auto 1fr */ + grid-template-columns: 1fr 15em; +} + +img { + max-width: 100%; +} + +/* Table of contents */ +#TOC { + grid-column: 2; + grid-row: 2; +} + +#TOC ul { + counter-reset: toc-heading; + list-style-type: none; + padding-left: 1.5em; +} + +#TOC li::before { + counter-increment: toc-heading; + content: counters(toc-heading, ".") ". "; +} + +header { + grid-row: 1; + grid-column: 1/3; + display: flex; + flex-direction: row; + justify-content: space-between; +} + +/* Breadcrumbs */ +#breadcrumb > * { + margin-left: 1ex; + margin-right: 1ex; +} + +/* */ + +main { + grid-column: 1; + grid-row: 2; +} + +footer { + border-top: 1px solid gray; + grid-column: 1/3; +} + +.tag { + background: lightgreen; + border-radius: 1ex; + font-size: 80%; + padding-left: 0.5ex; + padding-right: 0.7ex; + padding-top: 0.1ex; + padding-bottom: 0.2ex; + font-family: sans; +} + +/* +main h1 { font-size: 2em; color: #a54242; } +main h2 { font-size: 1.8em; color: #8c9440; } +main h3 { font-size: 1.6em; color: #5f819d; } +main h4 { font-size: 1.4em; color: #909090; } +main h5 { font-size: 1.2em; color: #989898; } +main h6 { font-size: 1em; color: #9c9c9c; } +*/ + +/* Numbered Headings in <main/> */ +main { + counter-reset: h1, h2, h3, h4, h5, h6; +} + +main h1 { counter-increment: h1; counter-reset: h2; } +main h2 { counter-increment: h2; counter-reset: h3; } +main h3 { counter-increment: h3; counter-reset: h4; } +main h4 { counter-increment: h4; counter-reset: h5; } +main h5 { counter-increment: h5; counter-reset: h6; } +main h6 { counter-increment: h6; } + +main h1::before { content: counter(h1) ". "; } +main h2::before { content: counter(h1) "." counter(h2) ". "; } +main h3::before { content: counter(h1) "." counter(h2) "." counter(h3) ". "; } +main h4::before { content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) ". "; } +main h5::before { content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) ". "; } +main h6::before { content: counter(h1) "." counter(h2) "." counter(h3) "." counter(h4) "." counter(h5) "." counter(h6) ". "; } + + +/* Syntax highlighting copied from Pandoc default stylesheet */ +code span.al { color: #ff0000; font-weight: bold; } /* Alert */ +code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */ +code span.at { color: #7d9029; } /* Attribute */ +code span.bn { color: #40a070; } /* BaseN */ +code span.bu { } /* BuiltIn */ +code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */ +code span.ch { color: #4070a0; } /* Char */ +code span.cn { color: #880000; } /* Constant */ +code span.co { color: #60a0b0; font-style: italic; } /* Comment */ +code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */ +code span.do { color: #ba2121; font-style: italic; } /* Documentation */ +code span.dt { color: #902000; } /* DataType */ +code span.dv { color: #40a070; } /* DecVal */ +code span.er { color: #ff0000; font-weight: bold; } /* Error */ +code span.ex { } /* Extension */ +code span.fl { color: #40a070; } /* Float */ +code span.fu { color: #06287e; } /* Function */ +code span.im { } /* Import */ +code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */ +code span.kw { color: #007020; font-weight: bold; } /* Keyword */ +code span.op { color: #666666; } /* Operator */ +code span.ot { color: #007020; } /* Other */ +code span.pp { color: #bc7a00; } /* Preprocessor */ +code span.sc { color: #4070a0; } /* SpecialChar */ +code span.ss { color: #bb6688; } /* SpecialString */ +code span.st { color: #4070a0; } /* String */ +code span.va { color: #19177c; } /* Variable */ +code span.vs { color: #4070a0; } /* VerbatimString */ +code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */ |