Skip to content

Commit

Permalink
experimentalbadge
Browse files Browse the repository at this point in the history
  • Loading branch information
viperehonchuk committed Jan 10, 2024
1 parent 2d33f8f commit 83aaac1
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ jobs:
- run: ls ./book
- run: ls .
- run: cp -r ./live-samples ./book/live-samples
- run: cp -r ./static ./book/static
- run: cp ./src/robots.txt ./book/robots.txt
- uses: actions/download-artifact@v3
with:
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ endif
.PHONY: build clean deploy install rebuild serve
.SHELLFLAGS += -e

book: book/live-samples book/uk
book: book/live-samples book/static book/uk

book/uk: book.toml content content/files/uk/index.md content/files/uk/SUMMARY.md original-content revamp/exe/move-media revamp/exe/format-links revamp/exe/inject-authors revamp/exe/revamp-html revamp/exe/rewire-paths revamp/exe/run-macros revamp/exe/strip-frontmatter revamp/exe/writer src
book/static: static
cp -r static ./book/static

book/uk: book.toml content content/files/uk/index.md content/files/uk/SUMMARY.md original-content revamp/exe/move-media revamp/exe/format-links revamp/exe/inject-authors revamp/exe/revamp-html revamp/exe/rewire-paths revamp/exe/run-macros revamp/exe/strip-frontmatter revamp/exe/writer src/script.js src/style.css
mdbook build
./revamp/exe/revamp-html
./revamp/exe/move-media
Expand Down
2 changes: 1 addition & 1 deletion hashes.json

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions revamp/preprocessors/src/helpers/render_html/abbr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package renderhtml

import (
"bytes"
"errors"
"html/template"
"log"
"strings"
)

var tAbbr *template.Template

type AbbrParams struct {
Class template.HTMLAttr
InnerHtml template.HTML
Text template.HTML
Title template.HTMLAttr
}

func RenderAbbr(params *AbbrParams) (string, error) {
if params.InnerHtml != "" && params.Text != "" {
return "", errors.New("in an abbr tag, either InnerHtml or Text must be set")
}
var b bytes.Buffer
err := tAbbr.Execute(&b, params)
if err != nil {
return "", err
}
return b.String(), nil
}

func init() {
var err error
tAbbr, err = template.ParseFiles("./revamp/preprocessors/src/helpers/render_html/templates/abbr.tmpl")
if err != nil && strings.Contains(err.Error(), "no such file") {
tAbbr, err = template.ParseFiles("../../helpers/render_html/templates/abbr.tmpl")
}
if err != nil {
log.Fatal(err)
}
}
1 change: 1 addition & 0 deletions revamp/preprocessors/src/helpers/render_html/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
var tSpan *template.Template

type SpanParams struct {
Class template.HTMLAttr
Style template.HTMLAttr
Text string
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<abbr class="{{ .Class }}" title="{{ .Title }}">{{if .InnerHtml}}{{.InnerHtml}}{{else}}{{.Text}}{{end}}</abbr>
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
<p style="{{ .Style }}">{{ .Text }}</p>
<p
class="{{ .Class }}"
style="{{ .Style }}"
>{{ .Text }}</p>
10 changes: 10 additions & 0 deletions revamp/preprocessors/src/run-macros/macros/experimental_inline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package macros

import (
"webdoky3/revamp/preprocessors/src/run-macros/environment"
"webdoky3/revamp/preprocessors/src/run-macros/registry"
)

func experimental_inline(env *environment.Environment, reg *registry.Registry, _ string) (string, error) {
return experimentalbadge(env, reg, "")
}
24 changes: 24 additions & 0 deletions revamp/preprocessors/src/run-macros/macros/experimentalbadge.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package macros

import (
"html/template"
renderhtml "webdoky3/revamp/preprocessors/src/helpers/render_html"
"webdoky3/revamp/preprocessors/src/run-macros/environment"
"webdoky3/revamp/preprocessors/src/run-macros/registry"
)

func experimentalbadge(env *environment.Environment, reg *registry.Registry, _ string) (string, error) {
// span, err := renderhtml.RenderSpan(&renderhtml.SpanParams{
// Class: template.HTMLAttr("visually-hidden"),
// Text: "Експериментальне",
// })
// if err != nil {
// return "", err
// }
return renderhtml.RenderAbbr(&renderhtml.AbbrParams{
Class: template.HTMLAttr("icon icon-experimental"),
// InnerHtml: template.HTML(span),
Text: "Експериментальне",
Title: template.HTMLAttr("Експериментальне. Поведінка цієї можливості в майбутньому може змінитися."),
})
}
2 changes: 2 additions & 0 deletions revamp/preprocessors/src/run-macros/macros/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ var MacrosIndex = map[string]func(*environment.Environment, *registry.Registry,
"embedghlivesample": embedghlivesample,
"embedinteractiveexample": embedinteractiveexample,
"embedlivesample": embedlivesample.Embedlivesample,
"experimental_inline": experimental_inline,
"experimentalbadge": experimentalbadge,
"glossary": glossary,
"glossarydisambiguation": glossarydisambiguation,
"glossarysidebar": blank,
Expand Down
32 changes: 32 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,36 @@ screen and (min-width: 1008px) {

.example-bad {
background-color: color-mix(in oklab, red 15%, var(--bg))
}

.visually-hidden {
clip: rect(1px, 1px, 1px, 1px) !important;
border: 0 !important;
-webkit-clip-path: inset(50%) !important;
clip-path: inset(50%) !important;
height: 1px !important;
margin: -1px !important;
overflow: hidden !important;
padding: 0 !important;
position: absolute !important;
white-space: nowrap !important;
width: 1px !important;
}

.icon {
--size: 1.8rem;
background-color: var(--icons);
display: inline-block;
flex-shrink: 0;
height: var(--size);
-webkit-mask-position: center;
mask-position: center;
-webkit-mask-repeat: no-repeat;
mask-repeat: no-repeat;
vertical-align: middle;
width: var(--size);
}

.icon.icon-experimental {
mask-image: url(/static/experimental.svg);
}
5 changes: 5 additions & 0 deletions static/experimental.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 83aaac1

Please sign in to comment.