-
-
Notifications
You must be signed in to change notification settings - Fork 489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support section variable in manual url #8494
base: main
Are you sure you want to change the base?
support section variable in manual url #8494
Conversation
I wonder if we want to make Of if we just want to treat is as required if want to use it. If we do want
Also you will need to update the following.
What do other think? |
@ianwallen I think it is fine if the placeholder is optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change works, but with the current code this kind of URL doesn't work:
https://something/subsection?lang=eng
The lang
placeholder replacement checks for /{{lang}}
instead of {{lang}}
. This is not changed in the PR, but not sure why the original code has the /
.
The official manual adds the language as part of the URL path, not as a parameter:
https://docs.geonetwork-opensource.org/4.4/fr/overview/
I assume you have some customised documentation that uses language as a parameter?
2e70774
to
0b000ce
Compare
The original has / is because it doesn't like to parse English into the default document. For example: https://docs.geonetwork-opensource.org/4.2/user-guide/describing-information/creating-metadata/ vs French version https://docs.geonetwork-opensource.org/4.2/fr/user-guide/describing-information/creating-metadata/. Now if we ignore that "/" logic, we will end up with default English url as: |
This reverts commit 0b000ce
Co-authored-by: Jose García <[email protected]>
if (baseUrl.includes("{{section}}")) { | ||
helpPageUrl = baseUrl.replace("{{section}}", page); | ||
} else { | ||
helpPageUrl = baseUrl + "/" + page; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add the "/"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the default original code.
core-geonetwork/web-ui/src/main/resources/catalog/components/common/needhelp/NeedHelpDirective.js
Line 160 in 97bdd7b
var helpPageUrl = baseUrl + "/" + page; |
The default manual.json of each section contains was appended at the end of the url and they contain no such "/". So the Javascript has to add them
core-geonetwork/web/src/main/webapp/WEB-INF/data/data/resources/config/manual.json
Line 2 in 97bdd7b
"creating-metadata": "user-guide/describing-information/creating-metadata/", |
@@ -152,20 +152,30 @@ | |||
if (gnGlobalSettings.lang !== "en") { | |||
baseUrl = scope.helpBaseUrl.replace("{{lang}}", gnGlobalSettings.lang); | |||
} else { | |||
baseUrl = scope.helpBaseUrl.replace("/{{lang}}", ""); | |||
baseUrl = scope.helpBaseUrl.replace("{{lang}}", ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be "."
i.e. there are 2 urls.
- If
lang !== "en"
i.e. fr - else
- https://docs.geonetwork-opensource.org/4.2/{{lang}}/api/search/
will be changed to - https://docs.geonetwork-opensource.org/4.2//api/search/
which does not look as pretty but still works. The double // in the url remains but if you put it as a "." then you get - https://docs.geonetwork-opensource.org/4.2/./api/search/
and the browser will replace this with - https://docs.geonetwork-opensource.org/4.2/api/search/
- https://docs.geonetwork-opensource.org/4.2/{{lang}}/api/search/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I think about it, it does not make sense to user "."
either because someone could use ?lang={{lang}}
and it would be odd to add "." and ?lang=.
would not make sense!
So I guess "" is better in this case.
Maybe there could be another replace on the url after the replace to remove all the double "//"
As for why there is a odd case where lang = ""
What if it treated gnGlobalSettings.lang !== "en"
as if gnGlobalSettings.lang = null
?
Then {{lang?en}}
could mean that if lang is null then default to en
So you could add another replacement for the following.
baseUrl = scope.helpBaseUrl.replace("{{lang?en}}", "");
So gn could use
https://docs.geonetwork-opensource.org/4.2/{{lang}}/api/search/
And other sites that always want to have a language value for language could use
https://example.com/{{lang?en}}/api/search/?lang={{lang?en}}
and it would result to en value.
But this would still be odd logic.
|
I would keep the replacement to empty string and replace Please check this change to apply it in your code: /**
* Processes an URL removing // characters in the URL path.
*
* @param url
* @returns {string}
*/
var processUrl = function(url) {
var urlToProcess = new URL(url);
urlToProcess.pathname = urlToProcess.pathname.replace(/\/\//g, "/");
return urlToProcess.toString();
}
scope.showHelp = function () {
...
var helpPageUrl;
if (baseUrl.includes("{{section}}")) {
helpPageUrl = baseUrl.replace("{{section}}", page);
} else {
helpPageUrl = baseUrl + "/" + page;
}
helpPageUrl = processUrl(helpPageUrl);
testAndOpen(helpPageUrl).then(
function () {},
function () {
var baseUrl = scope.helpBaseUrl
.replace("{{lang}}", "")
.replace("{{version}}", scope.applicationVersion);
var helpPageUrl;
if (baseUrl.includes("{{section}}")) {
helpPageUrl = baseUrl.replace("{{section}}", page);
} else {
helpPageUrl = baseUrl + "/" + page;
}
helpPageUrl = processUrl(helpPageUrl);
testAndOpen(helpPageUrl);
}
... |
…' into main.section.variable.manual.url
This approach works fine. I did apply this into the code, please check |
The manual url can be more flexible. In some places, the url can be like https://something/subsection?lang=eng ect. So I am adding section variable as part of the url pattern and the front end Javascript will handle this pattern as well.
Checklist
main
branch, backports managed with labelREADME.md
filespom.xml
dependency management. Update build documentation with intended library use and library tutorials or documentation