From df0c71260aaa86b9e9b0cafa7ac36dc07979b000 Mon Sep 17 00:00:00 2001 From: Yvonnick Esnault Date: Wed, 12 Aug 2020 10:44:44 +0200 Subject: [PATCH] feat(ui): serve current doc on /docs (#5364) * feat(ui): serve current doc on /docs Signed-off-by: Yvonnick Esnault --- Dockerfile | 3 +++ docs/config.toml | 5 +++-- docs/layouts/partials/head.html | 4 +--- docs/static/js/search.js | 9 +-------- engine/api/mail/mail.go | 9 --------- engine/ui/types.go | 1 + engine/ui/ui.go | 3 ++- engine/ui/ui_router.go | 13 +++++++++---- ui/src/app/shared/conditions/conditions.html | 2 +- ui/src/app/shared/keys/form/keys.form.html | 4 ++-- .../shared/requirements/form/requirements.form.html | 2 +- .../workflow/wizard/context/wizard.context.html | 2 +- .../app/shared/workflow/wizard/hook/hook.form.html | 2 +- .../workflow/wizard/node-add/node.wizard.html | 2 +- .../wizard/outgoinghook/wizard.outgoinghook.html | 2 +- .../form/worker-model-pattern.form.html | 8 ++++---- ui/src/app/views/application/show/application.html | 2 +- ui/src/app/views/navbar/navbar.html | 2 +- ui/src/app/views/pipeline/show/pipeline.show.html | 2 +- .../app/views/settings/action/help/action.help.html | 2 +- ui/src/app/views/settings/cdsctl/cdsctl.html | 2 +- .../worker-model/form/worker-model.form.html | 2 +- .../worker-model/help/worker-model.help.html | 8 ++++---- .../help/workflow-template.help.html | 2 +- .../list/workflow.notification.list.html | 2 +- ui/src/app/views/workflow/workflow.html | 4 ++-- ui/src/assets/i18n/en.json | 6 +++--- ui/src/assets/i18n/fr.json | 6 +++--- 28 files changed, 52 insertions(+), 59 deletions(-) diff --git a/Dockerfile b/Dockerfile index f6d8e47f49..24ccd3269f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,12 +7,15 @@ COPY dist/cdsctl-* /app/ COPY dist/cds-worker-* /app/ COPY dist/sql.tar.gz /app/ COPY dist/ui.tar.gz /app/ +COPY dist/cds-docs.tar.gz /app/ RUN groupadd -r cds && useradd --create-home -r -g cds cds RUN chmod +w /app/panic_dumps && \ chmod +x /app/cds-engine-linux-amd64 && \ tar xzf /app/sql.tar.gz -C /app/sql && \ tar xzf /app/ui.tar.gz -C /app/ui_static_files && \ + tar xzf /app/cds-docs.tar.gz -C /app/ui_static_files && \ + mv /app/ui_static_files/cds-docs /app/ui_static_files/docs && \ chown -R cds:cds /app USER cds WORKDIR /app diff --git a/docs/config.toml b/docs/config.toml index 98843734f7..d522bdff90 100644 --- a/docs/config.toml +++ b/docs/config.toml @@ -1,4 +1,4 @@ -baseURL = "https://ovh.github.io/cds" +baseURL = "" title = "CDS - Continuous Delivery Service" languageCode = "en-us" @@ -7,7 +7,8 @@ defaultContentLanguageInSubdir = false contentDir = "content" disableKinds = ["taxonomy", "taxonomyTerm"] -canonifyurls = true +canonifyurls = false +relativeURLs = true [outputs] home = [ "HTML", "RSS", "JSON"] diff --git a/docs/layouts/partials/head.html b/docs/layouts/partials/head.html index 1003a0cf0d..11d55cbd6c 100644 --- a/docs/layouts/partials/head.html +++ b/docs/layouts/partials/head.html @@ -39,10 +39,8 @@ - diff --git a/docs/static/js/search.js b/docs/static/js/search.js index 3f5f1a7f4f..17b2540ea2 100644 --- a/docs/static/js/search.js +++ b/docs/static/js/search.js @@ -7,12 +7,8 @@ function endsWith(str, suffix) { // Initialize lunrjs using our generated index file function initLunr() { - if (!endsWith(baseurl,"/")){ - baseurl = baseurl+'/' - }; - // First retrieve the index file - $.getJSON(baseurl +"index.json") + $.getJSON($('#indexJSON').attr('href')) .done(function(index) { pagesIndex = index; // Set up lunrjs by declaring the fields we use @@ -74,9 +70,6 @@ $( document ).ready(function() { item.context = text; var pathItem = item.uri; - if (pathItem.startsWith(baseurl)) { - pathItem = pathItem.slice(baseurl.length); - } if (endsWith(pathItem,"/")) { pathItem = pathItem.substring(0, pathItem.length-1); }; diff --git a/engine/api/mail/mail.go b/engine/api/mail/mail.go index e14fc355d4..69650c59dd 100644 --- a/engine/api/mail/mail.go +++ b/engine/api/mail/mail.go @@ -51,15 +51,6 @@ Regards, CDS Team ` -const templateReset = `Hi {{.Username}}, - -Your password was successfully reset. - -Regards, --- -CDS Team -` - // Init initializes configuration func Init(user, password, from, host, port string, tls, disable bool) { smtpUser = user diff --git a/engine/ui/types.go b/engine/ui/types.go index d478f28d9e..b6630f06b1 100644 --- a/engine/ui/types.go +++ b/engine/ui/types.go @@ -11,6 +11,7 @@ type Service struct { Cfg Configuration Router *api.Router HTMLDir string + DocsDir string } // Configuration is the ui configuration structure diff --git a/engine/ui/ui.go b/engine/ui/ui.go index 6111a9ce48..0b79142741 100644 --- a/engine/ui/ui.go +++ b/engine/ui/ui.go @@ -66,6 +66,7 @@ func (s *Service) ApplyConfiguration(config interface{}) error { // HTMLDir must contains the ui dist directory. // ui.tar.gz contains the dist directory s.HTMLDir = filepath.Join(s.Cfg.Staticdir, "dist") + s.DocsDir = filepath.Join(s.Cfg.Staticdir, "docs") s.Cfg.BaseURL = strings.TrimSpace(s.Cfg.BaseURL) if s.Cfg.BaseURL == "" { // s.Cfg.BaseURL could not be empty s.Cfg.BaseURL = "/" @@ -257,7 +258,7 @@ func (s *Service) askForGettingStaticFiles(ctx context.Context, version string) opts = append(opts, answerDoNothing) - ask := fmt.Sprintf("What do you want to do?") + ask := "What do you want to do?" selected := cli.AskChoice(ask, opts...) diff --git a/engine/ui/ui_router.go b/engine/ui/ui_router.go index 590e13050c..5fd6ddad6b 100644 --- a/engine/ui/ui_router.go +++ b/engine/ui/ui_router.go @@ -33,7 +33,8 @@ func (s *Service) initRouter(ctx context.Context) { r.Mux.PathPrefix(s.Cfg.DeployURL + "/cdshooks").Handler(s.getReverseProxy(s.Cfg.DeployURL+"/cdshooks", s.Cfg.HooksURL)) // serve static UI files - r.Mux.PathPrefix("/").Handler(s.uiServe(http.Dir(s.HTMLDir))) + r.Mux.PathPrefix("/docs").Handler(s.uiServe(http.Dir(s.DocsDir), s.DocsDir)) + r.Mux.PathPrefix("/").Handler(s.uiServe(http.Dir(s.HTMLDir), s.HTMLDir)) } func (s *Service) getReverseProxy(path, urlRemote string) *httputil.ReverseProxy { @@ -57,14 +58,18 @@ func (s *Service) getReverseProxy(path, urlRemote string) *httputil.ReverseProxy return &httputil.ReverseProxy{Director: director} } -func (s *Service) uiServe(fs http.FileSystem) http.Handler { +func (s *Service) uiServe(fs http.FileSystem, dir string) http.Handler { fsh := http.FileServer(fs) return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - r.URL.Path = strings.TrimPrefix(r.URL.Path, s.Cfg.DeployURL) + if dir == s.DocsDir { + r.URL.Path = strings.TrimPrefix(r.URL.Path, "/docs") + } else { + r.URL.Path = strings.TrimPrefix(r.URL.Path, s.Cfg.DeployURL) + } filePath := path.Clean(r.URL.Path) _, err := fs.Open(filePath) if os.IsNotExist(err) { - http.ServeFile(w, r, filepath.Join(s.HTMLDir, "index.html")) + http.ServeFile(w, r, filepath.Join(dir, "index.html")) return } fsh.ServeHTTP(w, r) diff --git a/ui/src/app/shared/conditions/conditions.html b/ui/src/app/shared/conditions/conditions.html index f7ad934ebb..560a3b8bcd 100644 --- a/ui/src/app/shared/conditions/conditions.html +++ b/ui/src/app/shared/conditions/conditions.html @@ -117,7 +117,7 @@

{{'workflow_node_condition_lua_title' | translate}}

{{'common_cds_documentation' | translate}}
diff --git a/ui/src/app/shared/keys/form/keys.form.html b/ui/src/app/shared/keys/form/keys.form.html index 97334c7f08..505716316e 100644 --- a/ui/src/app/shared/keys/form/keys.form.html +++ b/ui/src/app/shared/keys/form/keys.form.html @@ -1,10 +1,10 @@
- {{ 'keys_ssh_key_help' | translate }} Worker Install Key + {{ 'keys_ssh_key_help' | translate }} Worker Install Key
- {{ 'keys_pgp_key_help' | translate }} Worker Install Key + {{ 'keys_pgp_key_help' | translate }} Worker Install Key
diff --git a/ui/src/app/shared/requirements/form/requirements.form.html b/ui/src/app/shared/requirements/form/requirements.form.html index daf0fa3721..7f89cdb148 100644 --- a/ui/src/app/shared/requirements/form/requirements.form.html +++ b/ui/src/app/shared/requirements/form/requirements.form.html @@ -82,7 +82,7 @@

- + {{ 'requirement_documentation' | translate }}

diff --git a/ui/src/app/shared/workflow/wizard/context/wizard.context.html b/ui/src/app/shared/workflow/wizard/context/wizard.context.html index 9afb984b4c..9591fda5ca 100644 --- a/ui/src/app/shared/workflow/wizard/context/wizard.context.html +++ b/ui/src/app/shared/workflow/wizard/context/wizard.context.html @@ -91,7 +91,7 @@