mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 02:30:57 +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
|
@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("")
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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(""));
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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
|
||||||
});
|
});
|
||||||
|
|
|
@ -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("")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -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>
|
||||||
|
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue
Block a user