This repository has been archived by the owner on Nov 28, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved UI for custom redirect settings (#1775)
refs TryGhost/Ghost#12366 * Displays URL as absolute, but still stores the path relative to the site * Allows pasting absolute URL's or relative * Does not support external URL's * Removed redundant "Links" section in Portal settings sidebar Co-authored-by: Peter Zimon <zimo@ghost.org>
- Loading branch information
1 parent
e2dc14b
commit 42b845d
Showing
4 changed files
with
90 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<GhTextInput | ||
@value={{this.value}} | ||
@type="text" | ||
@input={{setValue}} | ||
/> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Component from '@glimmer/component'; | ||
import {action} from '@ember/object'; | ||
|
||
function ensureEndsWith(string, endsWith) { | ||
return string.endsWith(endsWith) ? string : string + endsWith; | ||
} | ||
|
||
function removeLeadingSlash(string) { | ||
return string.replace(/^\//, ''); | ||
} | ||
|
||
export default class GhUrlInput extends Component { | ||
constructor(owner, args) { | ||
super(owner, args); | ||
this.baseUrl = ensureEndsWith(args.baseUrl, '/'); | ||
this.value = args.value && args.value !== '/' ? (new URL(removeLeadingSlash(args.value), this.baseUrl)).href : ''; | ||
this.setResult = args.setResult; | ||
} | ||
|
||
@action | ||
setValue(event) { | ||
this.value = event.target.value; | ||
if (this.result !== null) { | ||
this.setResult(this.result); | ||
} | ||
} | ||
|
||
get result() { | ||
try { | ||
return new URL(removeLeadingSlash(this.value), this.baseUrl); | ||
} catch (err) { | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters