From 8b033c39933d55045f8ca6abb0fc3534bd4703c9 Mon Sep 17 00:00:00 2001 From: gcxfd Date: Mon, 21 Feb 2022 18:08:46 +0800 Subject: [PATCH] tools: add a `-theme-dir folder/` parameter to `v doc` (#13550) --- cmd/tools/vcomplete.v | 1 + cmd/tools/vdoc/html.v | 70 ++---------------- cmd/tools/vdoc/{resources => theme}/arrow.svg | 0 .../vdoc/{resources => theme}/dark-mode.js | 0 cmd/tools/vdoc/{resources => theme}/dark.svg | 0 cmd/tools/vdoc/{resources => theme}/doc.css | 0 cmd/tools/vdoc/{resources => theme}/doc.js | 0 .../favicons/android-chrome-192x192.png | Bin .../favicons/android-chrome-512x512.png | Bin .../favicons/apple-touch-icon.png | Bin .../favicons/browserconfig.xml | 0 .../favicons/favicon-16x16.png | Bin .../favicons/favicon-32x32.png | Bin .../{resources => theme}/favicons/favicon.ico | Bin .../favicons/mstile-144x144.png | Bin .../favicons/mstile-150x150.png | Bin .../favicons/mstile-310x150.png | Bin .../favicons/mstile-310x310.png | Bin .../favicons/mstile-70x70.png | Bin .../favicons/safari-pinned-tab.svg | 0 .../favicons/site.webmanifest | 0 cmd/tools/vdoc/theme/index.html | 63 ++++++++++++++++ cmd/tools/vdoc/{resources => theme}/light.svg | 0 cmd/tools/vdoc/{resources => theme}/link.svg | 0 cmd/tools/vdoc/{resources => theme}/menu.svg | 0 .../vdoc/{resources => theme}/normalize.css | 0 cmd/tools/vdoc/vdoc.v | 7 ++ cmd/v/help/doc.txt | 1 + 28 files changed, 77 insertions(+), 65 deletions(-) rename cmd/tools/vdoc/{resources => theme}/arrow.svg (100%) rename cmd/tools/vdoc/{resources => theme}/dark-mode.js (100%) rename cmd/tools/vdoc/{resources => theme}/dark.svg (100%) rename cmd/tools/vdoc/{resources => theme}/doc.css (100%) rename cmd/tools/vdoc/{resources => theme}/doc.js (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/android-chrome-192x192.png (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/android-chrome-512x512.png (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/apple-touch-icon.png (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/browserconfig.xml (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/favicon-16x16.png (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/favicon-32x32.png (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/favicon.ico (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/mstile-144x144.png (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/mstile-150x150.png (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/mstile-310x150.png (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/mstile-310x310.png (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/mstile-70x70.png (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/safari-pinned-tab.svg (100%) rename cmd/tools/vdoc/{resources => theme}/favicons/site.webmanifest (100%) create mode 100644 cmd/tools/vdoc/theme/index.html rename cmd/tools/vdoc/{resources => theme}/light.svg (100%) rename cmd/tools/vdoc/{resources => theme}/link.svg (100%) rename cmd/tools/vdoc/{resources => theme}/menu.svg (100%) rename cmd/tools/vdoc/{resources => theme}/normalize.css (100%) diff --git a/cmd/tools/vcomplete.v b/cmd/tools/vcomplete.v index cd4bb61c84..985a601643 100644 --- a/cmd/tools/vcomplete.v +++ b/cmd/tools/vcomplete.v @@ -203,6 +203,7 @@ const ( '-pos', '-no-timestamp', '-inline-assets', + '-theme-dir', '-open', '-p', '-s', diff --git a/cmd/tools/vdoc/html.v b/cmd/tools/vdoc/html.v index aa5c90ec14..574e13b52a 100644 --- a/cmd/tools/vdoc/html.v +++ b/cmd/tools/vdoc/html.v @@ -13,69 +13,8 @@ import v.pref const ( css_js_assets = ['doc.css', 'normalize.css', 'doc.js', 'dark-mode.js'] - res_path = os.resource_abs_path('resources') - favicons_path = os.join_path(res_path, 'favicons') + default_theme = os.resource_abs_path('theme') link_svg = '' - html_content = ' - - - - - - {{ title }} | vdoc - - - - - - - - - - - - {{ head_assets }} - - -
Skip to content
-
- -
-
-
-{{ contents }} - -
- {{ right_content }} -
-
-
- {{ footer_assets }} - - -' ) enum HighlightTokenTyp { @@ -150,7 +89,7 @@ fn (mut vd VDoc) render_static_html(out Output) { fn (vd VDoc) get_resource(name string, out Output) string { cfg := vd.cfg - path := os.join_path(res_path, name) + path := os.join_path(cfg.theme_dir, name) mut res := os.read_file(path) or { panic('vdoc: could not read $path') } /* if minify { @@ -301,8 +240,9 @@ fn (vd VDoc) gen_html(d doc.Doc) string { } modules_toc_str := modules_toc.str() symbols_toc_str := symbols_toc.str() - result := html_content.replace('{{ title }}', d.head.name).replace('{{ head_name }}', - header_name).replace('{{ version }}', version).replace('{{ light_icon }}', vd.assets['light_icon']).replace('{{ dark_icon }}', + result := (os.read_file(os.join_path(cfg.theme_dir, 'index.html')) or { panic(err) }).replace('{{ title }}', + d.head.name).replace('{{ head_name }}', header_name).replace('{{ version }}', + version).replace('{{ light_icon }}', vd.assets['light_icon']).replace('{{ dark_icon }}', vd.assets['dark_icon']).replace('{{ menu_icon }}', vd.assets['menu_icon']).replace('{{ head_assets }}', if cfg.inline_assets { '\n${tabs[0]}\n${tabs[0]}