<%= @heading %>
-<%= @heading %>
+-Källa: <%= @title %> -
- + <%= raw(@contents) %> ++ Källa: <%= @title %> +
+Delningar
++ Länkar som är värda att uppmärksammas och lämna åsikt om. +
+ <%= for {date, links} <- @links do %> +diff --git a/assets/app.css b/assets/app.css index 55bb4fb..11d454e 100644 --- a/assets/app.css +++ b/assets/app.css @@ -118,23 +118,6 @@ main { font-size: large; box-sizing: border-box; - > pre { - margin: 2em 0; - background-color: #022; - overflow-y: auto; - padding: 0.33em; - box-shadow: 4px 4px 0 #333; - position: relative; - line-height: 1.2; - font-size: 0.8em; - - > button { - position: absolute; - top: 0.25em; - right: 0.25em; - } - } - > footer { font-style: italic; text-align: right; @@ -142,6 +125,23 @@ main { } } +pre { + margin: 2em 0; + background-color: #022; + overflow-y: auto; + padding: 0.33em; + box-shadow: 4px 4px 0 #333; + position: relative; + line-height: 1.2; + font-size: 0.8em; + + > button { + position: absolute; + top: 0.25em; + right: 0.25em; + } +} + code { font-family: "JetBrains mono", monaco, menlo, meslo, "Courier New", Courier, monospace; @@ -193,3 +193,9 @@ section > h2 { padding: 0.25em 0.5em; } } + +.links { + > :is(h2, h3) { + margin-top: 3em; + } +} diff --git a/assets/js/app.js b/assets/js/app.js index 8fc7e57..3d91e67 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -44,6 +44,10 @@ import "../app.css"; -import copyToClipboard from "./copy-to-clipboard.js"; +import { + copyCodeToClipboard, + copyUrlToClipboard, +} from "./copy-to-clipboard.js"; -copyToClipboard(); +copyCodeToClipboard(); +copyUrlToClipboard(); diff --git a/assets/js/copy-to-clipboard.js b/assets/js/copy-to-clipboard.js index fa5d2db..5db1d66 100644 --- a/assets/js/copy-to-clipboard.js +++ b/assets/js/copy-to-clipboard.js @@ -1,14 +1,30 @@ -export default () => { +export const copyCodeToClipboard = () => { const codeblocks = document.querySelectorAll("pre>code"); - for (const b of codeblocks) { const button = document.createElement("button"); button.innerHTML = "Kopiera"; - button.addEventListener("click", function ({target}) { + button.addEventListener("click", function ({ target }) { const text = target.previousSibling.innerHTML; navigator.clipboard.writeText(text); - }) + }); b.parentNode.appendChild(button); } -} +}; +export const copyUrlToClipboard = () => { + const permalinks = document.querySelectorAll(".permalink"); + for (const pl of permalinks) { + pl.setAttribute( + "title", + pl.getAttribute("title") + ", klicka för att kopiera", + ); + pl.addEventListener("click", function (evt) { + const { target, shiftKey, ctrlKey, altKey } = evt; + if (!shiftKey && !ctrlKey && !altKey) { + evt.preventDefault(); + const text = target.href; + navigator.clipboard.writeText(text); + } + }); + } +}; diff --git a/lib/mse25/directus.ex b/lib/mse25/directus.ex index a6b4952..fc8fcbd 100644 --- a/lib/mse25/directus.ex +++ b/lib/mse25/directus.ex @@ -1,4 +1,6 @@ defmodule Mse25.Directus do + @draft_filter "filter[status][_eq]=published" + def get_article(slug) do get_item(:articles, slug) end @@ -173,6 +175,12 @@ defmodule Mse25.Directus do [base_url: base_url, token: token] = Application.fetch_env!(:mse25, :directus) req = Req.new(base_url: base_url <> "/items") + resource = + case String.contains?(resource, "?") do + true -> resource <> "&" <> @draft_filter + false -> resource <> "?" <> @draft_filter + end + case Req.get!(req, url: resource, auth: {:bearer, token}) |> payload do {:ok, payload} -> payload diff --git a/lib/mse25_web/components/layouts/root.html.heex b/lib/mse25_web/components/layouts/root.html.heex index bdb8948..6274a51 100644 --- a/lib/mse25_web/components/layouts/root.html.heex +++ b/lib/mse25_web/components/layouts/root.html.heex @@ -4,7 +4,7 @@ -
-Källa: <%= @title %> -
- + <%= raw(@contents) %> ++ Källa: <%= @title %> +
++ Länkar som är värda att uppmärksammas och lämna åsikt om. +
+ <%= for {date, links} <- @links do %> +