Skip to content

Commit

Permalink
feat: first version
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Mar 11, 2024
0 parents commit e5b3bdd
Show file tree
Hide file tree
Showing 23 changed files with 284 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
github: razonyang
custom:
- https://paypal.me/razonyang
15 changes: 15 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: lint

on:
push:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- uses: actions/setup-node@v4
with:
node-version: 16
# - run: npm ci
# - run: npm run lint
18 changes: 18 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
on:
push:
branches:
- main

permissions:
contents: write
pull-requests: write

name: release-please

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
with:
command: manifest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public/
resources/
.hugo_build.lock
node_modules/
14 changes: 14 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pull_request_rules:
- name: Automatic merge for Renovate pull requests
conditions:
- author=renovate[bot]
actions:
merge:
method: rebase

- name: Automatic merge on approval
conditions:
- "#approved-reviews-by>=1"
actions:
merge:
method: rebase
15 changes: 15 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"plugins": ["prettier-plugin-go-template"],
"bracketSameLine": true,
"goTemplateBracketSpacing": true,
"overrides": [
{
"files": [
"*.html"
],
"options": {
"parser": "go-template"
}
}
]
}
3 changes: 3 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
".": "0.0.1"
}
1 change: 1 addition & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.tmpl.scss
9 changes: 9 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "stylelint-config-standard-scss",
"rules": {
"at-rule-no-unknown": null,
"color-function-notation": null,
"scss/at-rule-no-unknown": true,
"scss/at-extend-no-missing-placeholder": null
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 HugoMods Authors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Hugo Kroki Module

[![Used By](https://flat.badgen.net/github/dependents-repo/hugomods/kroki?icon=github&label=used+by&color=green)](https://github.com/hugomods/kroki/network/dependents)
![Hugo Requirements](https://img.shields.io/badge/dynamic/json?color=important&label=requirements&query=requirements&logo=hugo&style=flat-square&url=https://api.razonyang.com/v1/hugo/modules/github.com/hugomods/kroki)
[![License](https://flat.badgen.net/github/license/hugomods/kroki)](https://github.com/hugomods/kroki/blob/main/LICENSE)
[![Version](https://flat.badgen.net/github/tag/hugomods/kroki)](https://github.com/hugomods/kroki/tags)
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/hugomods/kroki

go 1.18
Empty file added go.sum
Empty file.
3 changes: 3 additions & 0 deletions hugo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[params.kroki]
endpoint = "https://kroki.io/"
output = "inline"
9 changes: 9 additions & 0 deletions layouts/_default/_markup/render-codeblock-kroki.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{- $attrs := .Attributes }}
{{- $svg := partial "kroki/functions/svg" (dict "type" $attrs._type "source" .Inner) }}
{{- with $svg }}
{{ partial "kroki/output" (dict
"svg" .
"output" $attrs._output
"attrs" $attrs)
}}
{{- end }}
5 changes: 5 additions & 0 deletions layouts/partials/kroki/functions/attrs2str.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{- $attrs := slice }}
{{- range $k, $v := .Values }}
{{- $attrs = $attrs | append (printf `%s="%s"` $k $v) }}
{{- end }}
{{- return delimit $attrs " " }}
25 changes: 25 additions & 0 deletions layouts/partials/kroki/functions/svg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- $ctx := . }}
{{- if not $ctx.type }}
{{- errorf "[kroki] %s" "no diagram type specified" }}
{{- end }}
{{- $body := dict
"diagram_source" $ctx.source
"diagram_type" ($ctx.type | lower)
"output_format" "svg"
}}
{{- $opts := dict
"method" "post"
"body" ($body | jsonify)
"headers" (dict
"Content-Type" "application/json")
}}
{{- $url := site.Params.kroki.endpoint }}
{{- $resource := resources.GetRemote $url $opts }}
{{- with resources.GetRemote $url $opts }}
{{- with .Err }}
{{- errorf "[kroki] unable to generate diagrams: %s." . }}
{{- end }}
{{- else }}
{{- errorf "[kroki] unable to generate diagrams." }}
{{- end }}
{{- return $resource }}
38 changes: 38 additions & 0 deletions layouts/partials/kroki/output.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- $svg := .svg }}
{{- $output := default site.Params.kroki.output .output }}
{{- $attrs := newScratch }}
{{- range $key, $value := .attrs }}
{{- if or
(eq $key "type")
(eq $key "src")
(strings.HasPrefix $key "_")
}}
{{- continue }}
{{- end }}
{{- if eq $key "class" }}
{{- $value = printf "kroki %s" $value }}
{{- end }}
{{- $attrs.Set $key (string $value) }}
{{- end }}
{{- if eq $output "inline" }}
{{- $rawSVG := $svg.Content }}
{{- $matches := findRE `<svg[^>]+>` $rawSVG 1 }}
{{- with index $matches 0 }}
{{- range findRESubmatch `([\w\d\-]+)="([^"]+)"` . }}
{{- $key := index . 1 }}
{{- with index . 2 }}
{{- $attrs.Set $key . }}
{{- end }}
{{- end }}
{{- $newSVG := partial "kroki/functions/attrs2str" $attrs | printf "<svg %s>" }}
{{- $rawSVG = replaceRE `<svg[^>]+>` $newSVG $rawSVG 1 }}
{{- end }}
{{- $rawSVG | safeHTML }}
{{- else if eq $output "embed" }}
<embed
{{ with $attrs }}{{ partial "kroki/functions/attrs2str" . | safeHTMLAttr }}{{ end }}
type="image/svg+xml"
src="{{ $svg.RelPermalink }}" />
{{- else }}
{{- warnf "[kroki] unknown output: %s" $output }}
{{- end }}
21 changes: 21 additions & 0 deletions layouts/shortcodes/kroki.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- $name := .Get "_name" }}
{{- $type := .Get "_type" }}
{{- $output := .Get "_output" }}
{{- $source := "" }}
{{- with .Page.Resources.Get $name }}
{{- $source = .Content }}
{{- else }}
{{- with resources.Get $name }}
{{- $source = .Content }}
{{- end }}
{{- end }}
{{- with $source }}
{{- $svg := partial "kroki/functions/svg" (dict "type" $type "source" $source) }}
{{- with $svg }}
{{ partial "kroki/output" (dict
"svg" .
"output" $output
"attrs" $.Params)
}}
{{- end }}
{{- end }}
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "hugomods-kroki",
"repository": {
"type": "git",
"url": "git+https://github.com/hugomods/kroki.git"
},
"author": "Razon Yang <razonyang@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/hugomods/kroki/issues"
},
"homepage": "https://github.com/hugomods/kroki",
"devDependencies": {
"@tsconfig/recommended": "^1.0.2",
"prettier": "^3.0.0",
"prettier-plugin-go-template": "^0.0.15",
"stylelint": "^16.0.0",
"stylelint-config-standard-scss": "^13.0.0",
"stylelint-scss": "^6.0.0",
"ts-standard": "^12.0.2"
},
"scripts": {
"lint": "npm run eslint && npm run stylelint",
"eslint": "ts-standard",
"stylelint": "npx stylelint \"**/*.scss\""
}
}
22 changes: 22 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"monorepo-tags": true,
"release-type": "go",
"tag-separator": "/",
"changelog-sections": [
{ "type": "chore", "section": "Miscellaneous Chores", "hidden": true },
{ "type": "ci", "section": "Continuous Integration" },
{ "type": "docs", "section": "Documentation 📝" },
{ "type": "feat", "section": "Features ✨" },
{ "type": "feature", "section": "Features ✨" },
{ "type": "fix", "section": "Bug Fixes 🐞" },
{ "type": "perf", "section": "Performance Improvements ⚡️" },
{ "type": "style", "section": "Styles 🎨" }
],
"packages": {
".": {
"exclude-paths": [
]
}
}
}
13 changes: 13 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base"
],
"packageRules": [
{
"matchManagers": [ "gomod" ],
"matchDepTypes": [ "indirect" ],
"enabled": true
}
]
}
9 changes: 9 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "@tsconfig/recommended/tsconfig.json",
"compilerOptions": {
"preserveConstEnums": true,
"strictNullChecks": true
},
"include": ["assets/**/*"],
"exclude": ["node_modules"]
}

0 comments on commit e5b3bdd

Please sign in to comment.