mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 20:51:50 +08:00
Merge pull request #10519 from gschlager/get-url
Fixes for getURL() in subfolders and basePath in translations
This commit is contained in:
parent
e66f95de3a
commit
dac0e5b3cc
|
@ -107,7 +107,7 @@ export default Controller.extend(PeriodComputationMixin, {
|
|||
@discourseComputed
|
||||
trendingSearchDisabledLabel() {
|
||||
return I18n.t("admin.dashboard.reports.trending_search.disabled", {
|
||||
basePath: getURL("/")
|
||||
basePath: getURL("")
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@
|
|||
filters=trendingSearchFilters
|
||||
isEnabled=logSearchQueriesEnabled
|
||||
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>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
import { registerUnbound } from "discourse-common/lib/helpers";
|
||||
import getUrl from "discourse-common/lib/get-url";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
|
||||
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(""));
|
||||
|
|
|
@ -2,12 +2,14 @@ let cdn, baseUrl, baseUri;
|
|||
let S3BaseUrl, S3CDN;
|
||||
|
||||
export default function getURL(url) {
|
||||
if (!url) return url;
|
||||
|
||||
if (baseUri === undefined) {
|
||||
baseUri = $('meta[name="discourse-base-uri"]').attr("content") || "";
|
||||
}
|
||||
|
||||
if (!url) {
|
||||
return baseUri === "/" ? "" : baseUri;
|
||||
}
|
||||
|
||||
// if it's a non relative URL, return it.
|
||||
if (url !== "/" && !/^\/[^\/]/.test(url)) return url;
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ export default Component.extend({
|
|||
CATEGORY: category ? true : false,
|
||||
latestLink: opts.latestLink,
|
||||
catLink: opts.catLink,
|
||||
basePath: ""
|
||||
basePath: getURL("")
|
||||
});
|
||||
} else if (category) {
|
||||
return I18n.t("topic.read_more_in_category", opts);
|
||||
|
|
|
@ -31,7 +31,7 @@ export default Controller.extend(ModalFunctionality, {
|
|||
help() {
|
||||
this.setProperties({
|
||||
offerHelp: I18n.t("forgot_password.help", {
|
||||
basePath: getURL("/")
|
||||
basePath: getURL("")
|
||||
}),
|
||||
helpSeen: true
|
||||
});
|
||||
|
|
|
@ -58,7 +58,7 @@ const TopicDetails = RestModel.extend({
|
|||
} else {
|
||||
return I18n.t(localeString, {
|
||||
username: User.currentProp("username_lower"),
|
||||
basePath: getURL("/")
|
||||
basePath: getURL("")
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
{{/tap-tile-grid}}
|
||||
|
||||
{{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}}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -61,6 +61,12 @@ QUnit.test("getURL on subfolder install", assert => {
|
|||
"relative url has subfolder"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
getURL(""),
|
||||
"/forum",
|
||||
"relative url has subfolder without trailing slash"
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
getURL("/svg-sprite/forum.example.com/svg-sprite.js"),
|
||||
"/forum/svg-sprite/forum.example.com/svg-sprite.js",
|
||||
|
|
Loading…
Reference in New Issue
Block a user