mirror of
https://github.com/wassname/talk.git
synced 2026-07-14 11:18:50 +08:00
[next] Embed plus (#1877)
* Implement StreamEmbed instance and rename library to coral * Add article & articleButton.html, only show embed htmls in production * Respect assetURL * Add tests * Add parseHashQuery * Fix permalink query and integration tests * Fix permalink URL * Remove optionalparams from pym * Scroll when showing permalink view * Implement autoRender * AutoRender immediately when render permalink * Add test for `showPermalink` event * Add comment
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
export { default as buildURL } from "./buildURL";
|
||||
export { default as parseURL } from "./parseURL";
|
||||
export { default as modifyQuery } from "./modifyQuery";
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import modifyQuery from "./modifyQuery";
|
||||
|
||||
it("should modify query", () => {
|
||||
const testCases: Array<[string, Record<string, any>, string]> = [
|
||||
[
|
||||
"http://localhost:8080/?a=b#hash",
|
||||
{
|
||||
c: "d",
|
||||
},
|
||||
"http://localhost:8080/?a=b&c=d#hash",
|
||||
],
|
||||
[
|
||||
"http://localhost:8080/#hash",
|
||||
{
|
||||
a: "b",
|
||||
},
|
||||
"http://localhost:8080/?a=b#hash",
|
||||
],
|
||||
[
|
||||
"http://localhost:8080/?a=b#hash",
|
||||
{
|
||||
a: undefined,
|
||||
},
|
||||
"http://localhost:8080/#hash",
|
||||
],
|
||||
];
|
||||
testCases.forEach(([url, params, expected]) => {
|
||||
expect(modifyQuery(url, params)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import qs from "query-string";
|
||||
|
||||
import buildURL from "./buildURL";
|
||||
import parseURL from "./parseURL";
|
||||
|
||||
export default function modifyQuery(url: string, params: {}) {
|
||||
const parsed = parseURL(url);
|
||||
const query = qs.parse(parsed.search);
|
||||
parsed.search = qs.stringify({ ...query, ...params });
|
||||
return buildURL(parsed);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import parseHashQuery from "./parseHashQuery";
|
||||
|
||||
it("should parse hash", () => {
|
||||
const testCases: Array<[string, ReturnType<typeof parseHashQuery>]> = [
|
||||
[
|
||||
"#commentID=comment-id",
|
||||
{
|
||||
commentID: "comment-id",
|
||||
},
|
||||
],
|
||||
[
|
||||
"#commentID=comment-id&assetURL=asset-url",
|
||||
{
|
||||
commentID: "comment-id",
|
||||
assetURL: "asset-url",
|
||||
},
|
||||
],
|
||||
["#", {}],
|
||||
["", {}],
|
||||
];
|
||||
testCases.forEach(([url, expected]) => {
|
||||
expect(parseHashQuery(url)).toEqual(expected);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
import qs from "query-string";
|
||||
|
||||
export default function parseQueryHash(hash: string): Record<string, string> {
|
||||
return qs.parse(hash);
|
||||
}
|
||||
Reference in New Issue
Block a user