diff options
| author | MeiMei <30769358+mei23@users.noreply.github.com> | 2019-06-21 15:41:02 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2019-06-21 15:41:02 +0900 |
| commit | 16b03fc157507261c54e5bb0eb030dcf6418a68c (patch) | |
| tree | cda129a6a562bf156a6bfbed82a98bccaacff49a /src/client/app/common/scripts | |
| parent | Fix bug (diff) | |
| download | sharkey-16b03fc157507261c54e5bb0eb030dcf6418a68c.tar.gz sharkey-16b03fc157507261c54e5bb0eb030dcf6418a68c.tar.bz2 sharkey-16b03fc157507261c54e5bb0eb030dcf6418a68c.zip | |
Improve url-preview (#5077)
* url-previewリクエスト時にハッシュは除く
* ハッシュだけ違うプレビューカードは表示しない
* url-previewをユーザーロケールで出し分けるように
* Fix code style
Diffstat (limited to 'src/client/app/common/scripts')
| -rw-r--r-- | src/client/app/common/scripts/note-mixin.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/client/app/common/scripts/note-mixin.ts b/src/client/app/common/scripts/note-mixin.ts index 4b454f8800..e649680070 100644 --- a/src/client/app/common/scripts/note-mixin.ts +++ b/src/client/app/common/scripts/note-mixin.ts @@ -83,9 +83,19 @@ export default (opts: Opts = {}) => ({ if (this.appearNote.text) { const ast = parse(this.appearNote.text); // TODO: 再帰的にURL要素がないか調べる - return unique(ast + const urls = unique(ast .filter(t => ((t.node.type == 'url' || t.node.type == 'link') && t.node.props.url && !t.node.props.silent)) .map(t => t.node.props.url)); + + // unique without hash + // [ http://a/#1, http://a/#2, http://b/#3 ] => [ http://a/#1, http://b/#3 ] + const removeHash = x => x.replace(/#[^#]*$/, ''); + + return urls.reduce((array, url) => { + const removed = removeHash(url); + if (!array.map(x => removeHash(x)).includes(removed)) array.push(url); + return array; + }, []); } else { return null; } |