From b03b7dd061571f5cc2e715d1387ee5cfeadd847e Mon Sep 17 00:00:00 2001 From: nntrn <17685332+nntrn@users.noreply.github.com> Date: Thu, 11 Apr 2024 08:12:18 -0500 Subject: [PATCH] v3 --- Gemfile | 3 + _config.yml | 85 +++---------- _includes/sidebar.html | 15 +++ _includes/styles/highlight.css | 67 ++++++++++ _layouts/default.html | 31 +++++ _layouts/index.html | 13 ++ _layouts/minimal.html | 9 ++ _sass/color_schemes/custom.scss | 16 --- assets/style.css | 36 ++++++ recipes.jq | 212 +++----------------------------- scripts/build-recipes.sh | 14 +-- 11 files changed, 215 insertions(+), 286 deletions(-) create mode 100644 Gemfile create mode 100644 _includes/sidebar.html create mode 100644 _includes/styles/highlight.css create mode 100644 _layouts/default.html create mode 100644 _layouts/index.html create mode 100644 _layouts/minimal.html delete mode 100644 _sass/color_schemes/custom.scss create mode 100644 assets/style.css diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..ab38815 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem 'jekyll' \ No newline at end of file diff --git a/_config.yml b/_config.yml index 410449c..9883532 100644 --- a/_config.yml +++ b/_config.yml @@ -3,84 +3,33 @@ description: snippets for working with jq baseurl: "/jq-recipes" url: "https://nntrn.github.io" repository: nntrn/jq-recipes -recipes_file: recipes.jq - -remote_theme: just-the-docs/just-the-docs@v0.5.4 -heading_anchors: false -color_scheme: custom -markdown: kramdown -permalink: pretty -enable_copy_code_button: true - favicon_ico: "/assets/favicon.ico" -search_enabled: true -search: - # Maximum amount of previews per search result - previews: 3 - # Maximum amount of words to display before a matched word in the preview - preview_words_before: 3 - # Maximum amount of words to display after a matched word in the preview - preview_words_after: 3 - tokenizer_separator: /[^a-zA-Z0-9]+/ - rel_url: false - button: false - -nav_sort: case_sensitive - kramdown: - toc_levels: 2..2 smart_quotes: ["apos", "apos", "quot", "quot"] - + github_username: nntrn +stylesheets: + - styles/highlight.css + defaults: - scope: - path: "./functions/*.md" + path: "_functions" values: - parent: "Functions" + layout: minimal - scope: - path: "./general/*.md" + path: "_general" values: - parent: "General" - - scope: - path: "**index.html" - values: - has_children: true - layout: "default" - - scope: - path: "recipes.jq" - values: - output: true - -plugins: - - jekyll-remote-theme - -gh_edit_link: true -gh_edit_link_text: "Edit this page on GitHub" -gh_edit_repository: "https://github.com/nntrn/jq-recipes" -gh_edit_branch: "staging" -# gh_edit_source: docs # the source that your files originate from -gh_edit_view_mode: "tree" - -callouts_level: quiet -callouts: - highlight: - color: yellow - source: - title: Source - color: green - data: - title: Data - color: yellow - note: - title: Read more - color: blue + layout: minimal -custom_css: "/assets/custom/style.css" +collections: + general: + output: true + functions: + output: true -sass: - style: compact +sidebar: ["functions", "general"] compress_html: clippings: [div, p, ul, td, h1, h2] @@ -90,4 +39,8 @@ compress_html: blanklines: true profile: false -exclude: [readme.md] +exclude: + - readme.md + - Gemfile.lock + - _config.old.yml + - scripts diff --git a/_includes/sidebar.html b/_includes/sidebar.html new file mode 100644 index 0000000..91a759f --- /dev/null +++ b/_includes/sidebar.html @@ -0,0 +1,15 @@ + \ No newline at end of file diff --git a/_includes/styles/highlight.css b/_includes/styles/highlight.css new file mode 100644 index 0000000..2ccf97a --- /dev/null +++ b/_includes/styles/highlight.css @@ -0,0 +1,67 @@ +div.highlight code,pre>code{padding:1rem;display:block} +.highlight,pre.highlight{background:#f9f9f9;color:#383942} +.highlight pre{background:#f9f9f9} +.highlight .hll{background:#f9f9f9} +.highlight .c{color:#9fa0a6;font-style:italic} +.highlight .err{color:#fff;background-color:#e05151} +.highlight .k{color:#a625a4} +.highlight .l{color:#50a04f} +.highlight .n{color:#383942} +.highlight .o{color:#383942} +.highlight .p{color:#383942} +.highlight .cm{color:#9fa0a6;font-style:italic} +.highlight .cp{color:#9fa0a6;font-style:italic} +.highlight .c1{color:#9fa0a6;font-style:italic} +.highlight .cs{color:#9fa0a6;font-style:italic} +.highlight .ge{font-style:italic} +.highlight .gs{font-weight:700} +.highlight .kc{color:#a625a4} +.highlight .kd{color:#a625a4} +.highlight .kn{color:#a625a4} +.highlight .kp{color:#a625a4} +.highlight .kr{color:#a625a4} +.highlight .kt{color:#a625a4} +.highlight .ld{color:#50a04f} +.highlight .m{color:#b66a00} +.highlight .s{color:#50a04f} +.highlight .na{color:#b66a00} +.highlight .nb{color:#ca7601} +.highlight .nc{color:#ca7601} +.highlight .no{color:#ca7601} +.highlight .nd{color:#ca7601} +.highlight .ni{color:#ca7601} +.highlight .ne{color:#ca7601} +.highlight .nf{color:#383942} +.highlight .nl{color:#ca7601} +.highlight .nn{color:#383942} +.highlight .nx{color:#383942} +.highlight .py{color:#ca7601} +.highlight .nt{color:#e35549} +.highlight .nv{color:#ca7601} +.highlight .ow{font-weight:700} +.highlight .w{color:#f8f8f2} +.highlight .mf{color:#b66a00} +.highlight .mh{color:#b66a00} +.highlight .mi{color:#b66a00} +.highlight .mo{color:#b66a00} +.highlight .sb{color:#50a04f} +.highlight .sc{color:#50a04f} +.highlight .sd{color:#50a04f} +.highlight .s2{color:#50a04f} +.highlight .se{color:#50a04f} +.highlight .sh{color:#50a04f} +.highlight .si{color:#50a04f} +.highlight .sx{color:#50a04f} +.highlight .sr{color:#0083bb} +.highlight .s1{color:#50a04f} +.highlight .ss{color:#0083bb} +.highlight .bp{color:#ca7601} +.highlight .vc{color:#ca7601} +.highlight .vg{color:#ca7601} +.highlight .vi{color:#e35549} +.highlight .il{color:#b66a00} +.highlight .gu{color:#75715e} +.highlight .gd{color:#e05151} +.highlight .gi{color:#43d089} +.highlight .language-json .w+.s2{color:#e35549} +.highlight .language-json .kc{color:#0083bb} \ No newline at end of file diff --git a/_layouts/default.html b/_layouts/default.html new file mode 100644 index 0000000..a49ba96 --- /dev/null +++ b/_layouts/default.html @@ -0,0 +1,31 @@ + + + + + + + {% if page.title != 'Home' %}{{page.title|default:page.name}} | {%-endif %} {{site.title}} + + + + + + + + + +
+

{{site.title}}

+
+
+{{ content }} +
+ + + diff --git a/_layouts/index.html b/_layouts/index.html new file mode 100644 index 0000000..ce49107 --- /dev/null +++ b/_layouts/index.html @@ -0,0 +1,13 @@ +--- +layout: default +--- + +{%- assign list = site[page.title] %} +

{{page.title|upcase}}

+ \ No newline at end of file diff --git a/_layouts/minimal.html b/_layouts/minimal.html new file mode 100644 index 0000000..29dfe71 --- /dev/null +++ b/_layouts/minimal.html @@ -0,0 +1,9 @@ +--- +layout: default +--- +
+{% include sidebar.html %} +
+ {{content}} +
+
\ No newline at end of file diff --git a/_sass/color_schemes/custom.scss b/_sass/color_schemes/custom.scss deleted file mode 100644 index 9a212cd..0000000 --- a/_sass/color_schemes/custom.scss +++ /dev/null @@ -1,16 +0,0 @@ -$link-color: $blue-000; -$btn-primary-color: $blue-000; - -$body-background-color: $white !default; -$body-heading-color: $grey-dk-300 !default; -// $body-text-color: $grey-dk-100 !default; -$link-color: $grey-dk-000 !default; -// $nav-child-link-color: $grey-dk-100 !default; -$sidebar-color: #ffffff !default; -$base-button-color: #f7f7f7 !default; -// $btn-primary-color: $grey-dk-200 !default; -// $code-background-color: $grey-lt-000 !default; -$feedback-color: #eeeeee !default; -$table-background-color: $white !default; -$search-background-color: $white !default; -// $search-result-preview-color: $grey-dk-000 !default; diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..f8b433b --- /dev/null +++ b/assets/style.css @@ -0,0 +1,36 @@ +:root{--px-size:2.5%;--sans-serif:Helvetica Neue,Helvetica,Arial,sans-serif;--bull-margin:4px;--bull-symbol:"•";--underline-rgb:53,224,71;--underline-color:rgb(var(--underline-rgb));--meta-rgb:134,25,143;--body-rgb:34,34,34;--link-rgb:51,102,203;--meta-color:rgb(var(--meta-rgb));--body-color:rgb(var(--body-rgb));--h:126;--s:73.4%;--l:54%;--hsl:var(--h),var(--s),var(--l);--accent-color:hsl(var(--h), var(--s), var(--l));--gray:hsl(0, 0%, var(--l, 80%))} +*{box-sizing:border-box} +.hidden,[hidden]{display:none} +html{font-size:13px} +body{font-variant:proportional-width;scrollbar-width:thin;padding:0 0;margin:auto;font-family:var(--sans-serif);font-size:inherit;line-height:1.3;text-rendering:optimizeLegibility;font-variant:proportional-width} +a,u{text-underline-offset:1px;text-decoration-skip-ink:all;text-decoration-thickness:2px;text-decoration-skip-ink:none} +u{text-decoration-color:hsl(var(--h),var(--s),var(--l));text-decoration-skip-ink:all} +a:empty{text-decoration:none;color:inherit} +a:empty:after{content:attr(href)} +a:hover{text-decoration-color:currentColor} +a{color:inherit;text-decoration-color:hsl(var(--h),var(--s),var(--l))} +h1,h2,h3,h4,ul{margin:0 0} +h1,h2,h4{line-height:1} +.container{display:flex;gap:1rem;padding:1rem 0;width:100%} +footer,header,main{padding:0 1rem} +header{padding-top:1rem;padding-bottom:1rem} +footer{background:#222;min-height:100px;padding:1rem;color:#fff} +.container .sidebar{flex:1} +.container .content > *:first-child{padding:0 0;margin:0 0;margin-bottom:1rem} +.container .content{flex:3;width:100%;overflow-x:hidden} +.content h1{font-size:2rem;margin-bottom:1rem} +body{overflow-x:hidden} +pre{font-size:.9rem;max-width:100%} +pre code{white-space:pre;display:block;overflow-x:scroll} +button{position:fixed;z-index:1000;right:0} +.hidden,hidden{display:none!important} +.sidebar{flex-direction:column;background:#fff;color:#222} +.sidebar ul{padding:.5rem 2rem} +.flex{display:flex} +.gap{gap:var(--gap,1rem)} +.container{position:relative} +@media (max-width:600px){ +.container{flex-direction:column-reverse} +.sidebar{flex-direction:row;border-top:1px solid #222;padding-top:1rem} +.sidebar>div{flex:1;flex-wrap:wrap} +} diff --git a/recipes.jq b/recipes.jq index 0cb121b..a8eb857 100644 --- a/recipes.jq +++ b/recipes.jq @@ -9,9 +9,7 @@ # https://github.com/nntrn/jq-recipes # -########################################################################################## -# _site/functions/barcharts.md -########################################################################################## +# source: _functions/barcharts.md def barchart($key): length as $total @@ -48,9 +46,7 @@ def run_barchart: | flatten| join("\n") ; -########################################################################################## -# _site/functions/conversion.md -########################################################################################## +# source: _functions/conversion.md def to_precision($p): . |tostring|split(".") @@ -68,162 +64,7 @@ def humansize(bytes;$p): def humansize(bytes): humansize(bytes;1); -########################################################################################## -# _site/functions/json2csv.md -########################################################################################## - -def json2csv: - (map(keys) | add | unique) as $cols - | map(. as $row | $cols | map($row[.])) as $rows - | $cols, $rows[] - | @csv; - -########################################################################################## -# _site/functions/pick.md -########################################################################################## - -def pick(stream): - . as $in - | reduce path(stream) as $a (null; - setpath($a; $in|getpath($a)) ); - -########################################################################################## -# _site/functions/read-history.md -########################################################################################## - -def history: - map( - if test("#[0-9]{10,12}") - then "\(.|gsub("#";"")|tonumber|todate)" - else "\t\(.)\n" - end - ) | join(""); - -########################################################################################## -# _site/functions/summary.md -########################################################################################## - -def grouped_summary($item): - {"\($item? // "blank")":group_by(.[$item])|map({"\(.[0][$item]? // "blank")":length})|add}; - -def summary: - [ (.[0]|keys)[] as $keys | grouped_summary($keys)] - | add - | to_entries - | map( - del(select(((.value//"")|keys[0]|length) > 100)) | - del(select(((.value//"")|values|length) > 400)) - ) - | map(select(.)) - | from_entries; - -def summary_wip: - [ (.[0]|keys)[] as $keys | grouped_summary($keys)] - | add - | to_entries - #| map(del(select(((.value//"")|keys|length) > 400))) - | map(select(.)|{key,count:(.value|length)}) - | map(.value |= to_entries); - -def summary2: - . as $data - | (.[0]|keys) - | map(. as $item | { - key: $item, - value: ($data|map(.[$item])|group_by(.)|map({"\(.[0])": length}))|add - }) - | map(select((.value|to_entries|length)< (.90 * ($data|length)))) - | from_entries; - -########################################################################################## -# _site/general/codepoints.md -########################################################################################## - -def smart_squotes($s): - $s | if (test("[\\s\\n\\t]";"x")) then "\([39]|implode)\($s)\([39]|implode)" else $s end; - -def smart_dquotes($s): - $s | if (test("[\\s\\n\\t]";"x")) then "\($s|@json)" else $s end; - -########################################################################################## -# _site/general/reduce.md -########################################################################################## - -def tocsv: - .[0] as $cols | .[1:] - | map(. as $row - | $cols - | with_entries({ "key": .value,"value": $row[.key]}) - ); - -########################################################################################## -# _site/general/wrangle.md -########################################################################################## - -def s: [splits(" +")]; - -########################################################################################## -# functions/barcharts.md -########################################################################################## - -def barchart($key): - length as $total - | map((.[$key] // "null") | tostring) - | group_by(.) - | (map({ key: .[0], value: length, title_len: (.[0]|tostring|length) }) ) as $columns - | $columns - | sort_by(.value) | reverse - | (max_by(.title_len)|.title_len) as $padding - | - (if (((($columns|length)/$total) > .8) or (($columns|length) > 1000)) then - [ "IGNORING <\($key)>: \($columns|length) out of \($total) rows", ""] - else [ - $key, - ("-" * ($key|length) ), - map( - [ - .key, (" " * ($padding-.title_len)), - "\((.value/$total)*100|tostring|.+".000"|.[0:4])%", - ( if (.value == 1) then "▊" else ("█" * (((.value/$total)*100) + (.value|log)|round)) end), - .value - ] | join(" ") - ), - "" - ] end) - | flatten - | join("\n"); - -def run_barchart: - . as $data - | (.[0]|keys) as $cols - | ($cols | map(. as $col | $data | barchart($col)) | join("\n")) as $barcharts - | [ $barcharts ] - | flatten| join("\n") -; - -########################################################################################## -# functions/conversion.md -########################################################################################## - -def to_precision($p): - . |tostring|split(".") - | [.[0], (.[1]|split("")|.[0:($p|tonumber)]|join(""))] - | join(".") - | tonumber; - -def humansize(bytes;$p): - (bytes|tonumber) as $size | - if $size > 1073741824 then "\(($size/1073741824)|to_precision($p))G" - elif $size > 1048576 then "\(($size/1048576)|to_precision($p))M" - elif $size > 1024 then "\(($size/1024)|to_precision($p))K" - else $size - end; - -def humansize(bytes): humansize(bytes;1); - -########################################################################################## -# functions/describe.md -########################################################################################## +# source: _functions/describe.md def describe: walk( @@ -238,9 +79,7 @@ def describe: end ); -########################################################################################## -# functions/flatten.md -########################################################################################## +# source: _functions/flatten.md def flat_object: [paths(scalars) as $path @@ -250,9 +89,7 @@ def flat_object: def flat_array: map( flat_object ); -########################################################################################## -# functions/github-api.md -########################################################################################## +# source: _functions/github-api.md def github_raw_url: [ @@ -261,9 +98,7 @@ def github_raw_url: (if .repository.private then " -H \"Authorization: Bearer $GITHUB_TOKEN\"" else "" end) ] | join(""); -########################################################################################## -# functions/json2csv.md -########################################################################################## +# source: _functions/json2csv.md def json2csv: (map(keys) | add | unique) as $cols @@ -271,18 +106,17 @@ def json2csv: | $cols, $rows[] | @csv; -########################################################################################## -# functions/pick.md -########################################################################################## +# source: _functions/pick.md def pick(stream): . as $in | reduce path(stream) as $a (null; setpath($a; $in|getpath($a)) ); -########################################################################################## -# functions/read-history.md -########################################################################################## +def spick($key): + getpath([($key|split(".")[]|select(length > 0))]); + +# source: _functions/read-history.md def history: map( @@ -292,9 +126,7 @@ def history: end ) | join(""); -########################################################################################## -# functions/summary.md -########################################################################################## +# source: _functions/summary.md def grouped_summary($item): {"\($item? // "blank")":group_by(.[$item])|map({"\(.[0][$item]? // "blank")":length})|add}; @@ -328,9 +160,7 @@ def summary2: | map(select((.value|to_entries|length)< (.90 * ($data|length)))) | from_entries; -########################################################################################## -# functions/text.md -########################################################################################## +# source: _functions/text.md def split_newlines($s): if ((type == "string") and (($s|tostring|split("\n")|length) > 1)?) @@ -348,9 +178,7 @@ def dquote($text): "\"\($text)\""; def unsmart($text): $text | gsub("[“”]";"\"") | gsub("[’‘]";"'"); def unsmart: . | unsmart; -########################################################################################## -# functions/unroll.md -########################################################################################## +# source: _functions/unroll.md def categorize: # Returns "object", "array" or "scalar" to indicate the category @@ -413,9 +241,7 @@ def unroll: def unrolls($data): { data: $data, state: $data| split, result: [] } | unroll ; def unrolls: unrolls(.); -########################################################################################## -# general/codepoints.md -########################################################################################## +# source: _general/codepoints.md def smart_squotes($s): $s | if (test("[\\s\\n\\t]";"x")) then "\([39]|implode)\($s)\([39]|implode)" else $s end; @@ -423,9 +249,7 @@ def smart_squotes($s): def smart_dquotes($s): $s | if (test("[\\s\\n\\t]";"x")) then "\($s|@json)" else $s end; -########################################################################################## -# general/reduce.md -########################################################################################## +# source: _general/reduce.md def tocsv: .[0] as $cols | .[1:] @@ -434,9 +258,7 @@ def tocsv: | with_entries({ "key": .value,"value": $row[.key]}) ); -########################################################################################## -# general/wrangle.md -########################################################################################## +# source: _general/wrangle.md def s: [splits(" +")]; diff --git a/scripts/build-recipes.sh b/scripts/build-recipes.sh index b32bcca..eacb613 100755 --- a/scripts/build-recipes.sh +++ b/scripts/build-recipes.sh @@ -16,19 +16,15 @@ BANNER="# # # SOURCE # https://github.com/nntrn/jq-recipes -#" - -BORDER="##########################################################################################" +# +" build() { echo "$BANNER" - echo - head -n 1000 $(grep --include "*.md" -rlE '^def ' . | sort) | + head -n 1000 $(grep --exclude-dir "_site" --include "*.md" -rlE '^def ' _* | sort) | sed 's,^`.*,,g; s,<==$,\n,g' | - sed -nE '/^==>|^def/,/^$/p' | - sed -E 's,^==> \./(.*)$,\n# \1 \n,g' | - sed "s,,$BORDER,g" + sed -nE '/^==>|^def/,/^$/p' | sed 's,^==> ,\n# source: ,g' } -build | tee $JQFILE +build | cat -s | tee $JQFILE jq -nr -L . 'include "recipes"; try error("has error") catch ""'