mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
7833da8365
refs https://github.com/TryGhost/Team/issues/1488 - Includes a new component that fetches the latest X newsletters. - Displays these newsletters using design from old dashboard. - Currently shows 10 newsletters, but we'll want to change that later. - Temporary CSS class added.
35 lines
900 B
JavaScript
35 lines
900 B
JavaScript
import {helper} from '@ember/component/helper';
|
|
|
|
/**
|
|
* Usage:
|
|
*
|
|
* ```hbs
|
|
* {{set-url-query 'https://myurl.com' utm_source='admin'}}
|
|
* ```
|
|
*
|
|
* This example will return https://myurl.com?utm_source=admin
|
|
*
|
|
* You can set every query/search parameter you want. It will override existing paramters if they are already set.
|
|
*/
|
|
export function setQueryParams([url], parameters) {
|
|
if (url) {
|
|
// Do some magic
|
|
try {
|
|
const parsed = new URL(url);
|
|
for (const key of Object.keys(parameters)) {
|
|
parsed.searchParams.set(key, parameters[key]);
|
|
}
|
|
return parsed.href;
|
|
} catch (e) {
|
|
// Invalid url. Just pass the original.
|
|
// eslint-disable-next-line no-console
|
|
console.error(e);
|
|
return url;
|
|
}
|
|
}
|
|
|
|
return '';
|
|
}
|
|
|
|
export default helper(setQueryParams);
|