copy link to clipboard with hyperscript

This commit is contained in:
Dmitry Zuikov 2024-03-31 13:26:07 +03:00
parent a1e3b081ca
commit e14c559dca
3 changed files with 25 additions and 6 deletions

View File

@ -38,9 +38,14 @@ getConfigDir = do
getManifest :: GitPerks m => m (Text, Text, Maybe Text)
getManifest = do
dir <- getConfigDir
dirFull <- expandPath dir
let mf = dir </> "manifest"
let defname = takeFileName (takeDirectory dir) & Text.pack
-- directory/.hbs2-git/manifest
-- so, it should be:
let defname = takeFileName (takeDirectory dirFull) & Text.pack
let defbrief = "n/a"
content <- liftIO (try @_ @IOException $ readFile mf)
@ -88,3 +93,4 @@ export include "refs/heads/main"
export exclude "refs/heads/*"
export tags
|]

View File

@ -5,7 +5,8 @@ import HBS2.Git.Oracle.State
import Data.HashMap.Strict (HashMap)
import Lucid (Html,HtmlT,toHtml,toHtmlRaw,renderBS)
import Lucid hiding (for_)
import Lucid.Base
import Lucid.Html5 hiding (for_)
import Data.Text (Text)
@ -15,7 +16,7 @@ import Data.HashMap.Strict qualified as HM
import Data.ByteString.Lazy
import Text.Pandoc
import Text.Pandoc.Error (handleError)
import Text.InterpolatedString.Perl6 (qc)
markdownToHtml :: Text -> Either PandocError String
markdownToHtml markdown = runPure $ do
@ -29,6 +30,14 @@ renderMarkdown markdown = case markdownToHtml markdown of
Right html -> toHtmlRaw $ Text.pack html
-- FIXME: move-to-hbs2-browser-lib
hyper_ :: Text -> Attribute
hyper_ = makeAttribute "_"
-- FIXME: move-to-hbs2-browser-lib
onClickCopy :: Text -> Attribute
onClickCopy s = hyper_ [qc|on click writeText('{s}') into the navigator's clipboard|]
renderEntries :: Monad m => HashMap Text Text -> [(HashVal, Text, Text, Word64)] -> m ByteString
renderEntries args items = pure $ renderBS do
wrapped do
@ -47,12 +56,13 @@ renderEntries args items = pure $ renderBS do
let s = if Text.length n > 2 then n else "unnamed"
let refpart = Text.take 8 $ Text.pack $ show $ pretty h
let ref = Text.pack $ show $ pretty h
div_ [class_ "repo-list-item"] do
div_ [class_ "repo-info"] do
h2_ $ a_ [href_ ""] $ toHtml (s <> "-" <> refpart)
h2_ $ a_ [href_ "", onClickCopy ref] $ toHtml (s <> "-" <> refpart)
a_ [href_ ""] (toHtml (show $ pretty h))
a_ [href_ "", hyper_ ""] (toHtml (show $ pretty h))
renderMarkdown b

View File

@ -56,11 +56,13 @@ input[type="search"] {
button.search {
background: url('/icon/refresh.svg') no-repeat center center;
background-size: 24px 24px;
fill: white;
min-width: 32px;
height: 2.5rem;
}
button.search svg {
}
body, html {
margin: 0;
height: 100%;
@ -243,6 +245,7 @@ rootPage content = do
meta_ [name_ "viewport", content_ "width=device-width, initial-scale=1.0"]
-- link_ [rel_ "stylesheet", href_"/css/pico.min.css"]
link_ [rel_ "stylesheet", href_ "https://cdn.jsdelivr.net/npm/@picocss/pico@2.0.6/css/pico.min.css"]
script_ [src_ "https://unpkg.com/hyperscript.org@0.9.12"] ""
myCss
body_ do