Merge pull request #10519 from gschlager/get-url

Fixes for getURL() in subfolders and basePath in translations
This commit is contained in:
Gerhard Schlager 2020-08-25 11:42:50 +02:00 committed by GitHub
parent e66f95de3a
commit dac0e5b3cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 22 additions and 9 deletions

View File

@ -107,7 +107,7 @@ export default Controller.extend(PeriodComputationMixin, {
@discourseComputed @discourseComputed
trendingSearchDisabledLabel() { trendingSearchDisabledLabel() {
return I18n.t("admin.dashboard.reports.trending_search.disabled", { return I18n.t("admin.dashboard.reports.trending_search.disabled", {
basePath: getURL("/") basePath: getURL("")
}); });
}, },

View File

@ -147,7 +147,7 @@
filters=trendingSearchFilters filters=trendingSearchFilters
isEnabled=logSearchQueriesEnabled isEnabled=logSearchQueriesEnabled
disabledLabel=trendingSearchDisabledLabel}} disabledLabel=trendingSearchDisabledLabel}}
{{html-safe (i18n "admin.dashboard.reports.trending_search.more" basePath=(base-url))}} {{html-safe (i18n "admin.dashboard.reports.trending_search.more" basePath=(base-path))}}
</div> </div>
{{/if}} {{/if}}
</div> </div>

View File

@ -1,5 +1,10 @@
import { registerUnbound } from "discourse-common/lib/helpers"; import { registerUnbound } from "discourse-common/lib/helpers";
import getUrl from "discourse-common/lib/get-url"; import getUrl from "discourse-common/lib/get-url";
import deprecated from "discourse-common/lib/deprecated";
registerUnbound("get-url", value => getUrl(value)); registerUnbound("get-url", value => getUrl(value));
registerUnbound("base-url", () => getUrl("")); registerUnbound("base-url", () => {
deprecated("Use `{{base-path}}` instead of `{{base-url}}`");
return getUrl("");
});
registerUnbound("base-path", () => getUrl(""));

View File

@ -2,12 +2,14 @@ let cdn, baseUrl, baseUri;
let S3BaseUrl, S3CDN; let S3BaseUrl, S3CDN;
export default function getURL(url) { export default function getURL(url) {
if (!url) return url;
if (baseUri === undefined) { if (baseUri === undefined) {
baseUri = $('meta[name="discourse-base-uri"]').attr("content") || ""; baseUri = $('meta[name="discourse-base-uri"]').attr("content") || "";
} }
if (!url) {
return baseUri === "/" ? "" : baseUri;
}
// if it's a non relative URL, return it. // if it's a non relative URL, return it.
if (url !== "/" && !/^\/[^\/]/.test(url)) return url; if (url !== "/" && !/^\/[^\/]/.test(url)) return url;

View File

@ -63,7 +63,7 @@ export default Component.extend({
CATEGORY: category ? true : false, CATEGORY: category ? true : false,
latestLink: opts.latestLink, latestLink: opts.latestLink,
catLink: opts.catLink, catLink: opts.catLink,
basePath: "" basePath: getURL("")
}); });
} else if (category) { } else if (category) {
return I18n.t("topic.read_more_in_category", opts); return I18n.t("topic.read_more_in_category", opts);

View File

@ -31,7 +31,7 @@ export default Controller.extend(ModalFunctionality, {
help() { help() {
this.setProperties({ this.setProperties({
offerHelp: I18n.t("forgot_password.help", { offerHelp: I18n.t("forgot_password.help", {
basePath: getURL("/") basePath: getURL("")
}), }),
helpSeen: true helpSeen: true
}); });

View File

@ -58,7 +58,7 @@ const TopicDetails = RestModel.extend({
} else { } else {
return I18n.t(localeString, { return I18n.t(localeString, {
username: User.currentProp("username_lower"), username: User.currentProp("username_lower"),
basePath: getURL("/") basePath: getURL("")
}); });
} }
}, },

View File

@ -99,7 +99,7 @@
{{/tap-tile-grid}} {{/tap-tile-grid}}
{{else}} {{else}}
<div class="alert alert-info">{{html-safe (i18n "bookmarks.no_timezone" basePath=(base-uri))}}</div> <div class="alert alert-info">{{html-safe (i18n "bookmarks.no_timezone" basePath=(base-path))}}</div>
{{/if}} {{/if}}
</div> </div>

View File

@ -61,6 +61,12 @@ QUnit.test("getURL on subfolder install", assert => {
"relative url has subfolder" "relative url has subfolder"
); );
assert.equal(
getURL(""),
"/forum",
"relative url has subfolder without trailing slash"
);
assert.equal( assert.equal(
getURL("/svg-sprite/forum.example.com/svg-sprite.js"), getURL("/svg-sprite/forum.example.com/svg-sprite.js"),
"/forum/svg-sprite/forum.example.com/svg-sprite.js", "/forum/svg-sprite/forum.example.com/svg-sprite.js",