2018-02-05 14:25:19 +09:00
|
|
|
<template>
|
2019-02-28 03:46:37 +09:00
|
|
|
<div v-if="playerEnabled" class="player" :style="`padding: ${(player.height || 0) / (player.width || 1) * 100}% 0 0`">
|
2019-03-12 13:12:34 +09:00
|
|
|
<button class="disablePlayer" @click="playerEnabled = false" :title="$t('disable-player')"><fa icon="times"/></button>
|
2019-02-28 03:46:37 +09:00
|
|
|
<iframe :src="player.url + (player.url.match(/\?/) ? '&autoplay=1&auto_play=1' : '?autoplay=1&auto_play=1')" :width="player.width || '100%'" :heigth="player.height || 250" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen />
|
2018-08-23 00:34:35 +09:00
|
|
|
</div>
|
2018-07-26 04:55:39 +09:00
|
|
|
<div v-else-if="tweetUrl && detail" class="twitter">
|
|
|
|
<blockquote ref="tweet" class="twitter-tweet" :data-theme="$store.state.device.darkmode ? 'dark' : null">
|
|
|
|
<a :href="url"></a>
|
|
|
|
</blockquote>
|
|
|
|
</div>
|
2018-04-22 19:33:06 +09:00
|
|
|
<div v-else class="mk-url-preview">
|
2019-05-27 18:01:06 +09:00
|
|
|
<component :is="hasRoute ? 'router-link' : 'a'" :class="{ mini: narrow, compact }" :[attr]="hasRoute ? url.substr(local.length) : url" rel="nofollow noopener" :target="target" :title="url" v-if="!fetching">
|
2019-02-28 03:46:37 +09:00
|
|
|
<div class="thumbnail" v-if="thumbnail" :style="`background-image: url('${thumbnail}')`">
|
|
|
|
<button v-if="!playerEnabled && player.url" @click.prevent="playerEnabled = true" :title="$t('enable-player')"><fa :icon="['far', 'play-circle']"/></button>
|
|
|
|
</div>
|
2018-03-19 02:56:35 +09:00
|
|
|
<article>
|
|
|
|
<header>
|
2019-01-06 12:56:13 +09:00
|
|
|
<h1 :title="title">{{ title }}</h1>
|
2018-03-19 02:56:35 +09:00
|
|
|
</header>
|
2019-01-06 12:56:13 +09:00
|
|
|
<p v-if="description" :title="description">{{ description.length > 85 ? description.slice(0, 85) + '…' : description }}</p>
|
2018-03-19 02:56:35 +09:00
|
|
|
<footer>
|
|
|
|
<img class="icon" v-if="icon" :src="icon"/>
|
2019-01-06 12:56:13 +09:00
|
|
|
<p :title="sitename">{{ sitename }}</p>
|
2018-03-19 02:56:35 +09:00
|
|
|
</footer>
|
|
|
|
</article>
|
2019-05-24 19:19:43 +09:00
|
|
|
</component>
|
2018-03-19 02:56:35 +09:00
|
|
|
</div>
|
2018-02-05 14:25:19 +09:00
|
|
|
</template>
|
|
|
|
|
2018-02-11 23:35:32 +09:00
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2019-02-28 03:46:37 +09:00
|
|
|
import i18n from '../../../i18n';
|
2019-06-21 15:41:02 +09:00
|
|
|
import { url as local, lang } from '../../../config';
|
2018-02-11 23:35:32 +09:00
|
|
|
|
|
|
|
export default Vue.extend({
|
2019-02-28 03:46:37 +09:00
|
|
|
i18n: i18n('common/views/components/url-preview.vue'),
|
2019-05-24 19:19:43 +09:00
|
|
|
|
2018-07-26 04:55:39 +09:00
|
|
|
props: {
|
|
|
|
url: {
|
|
|
|
type: String,
|
|
|
|
require: true
|
|
|
|
},
|
2018-08-30 03:32:42 +09:00
|
|
|
|
2018-07-26 04:55:39 +09:00
|
|
|
detail: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
2018-09-01 13:08:43 +09:00
|
|
|
},
|
|
|
|
|
2019-01-06 12:56:13 +09:00
|
|
|
compact: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false
|
|
|
|
},
|
2019-02-25 19:45:00 +09:00
|
|
|
},
|
2019-01-06 12:56:13 +09:00
|
|
|
|
2019-02-25 19:45:00 +09:00
|
|
|
inject: {
|
|
|
|
narrow: {
|
2018-09-01 13:08:43 +09:00
|
|
|
default: false
|
2018-07-26 04:55:39 +09:00
|
|
|
}
|
|
|
|
},
|
2018-08-30 03:32:42 +09:00
|
|
|
|
2018-02-11 23:35:32 +09:00
|
|
|
data() {
|
2019-05-27 18:01:06 +09:00
|
|
|
const isSelf = this.url.startsWith(local);
|
|
|
|
const hasRoute =
|
2019-07-06 22:53:15 +09:00
|
|
|
(this.url.substr(local.length) === '/') ||
|
2019-05-27 18:01:06 +09:00
|
|
|
this.url.substr(local.length).startsWith('/@') ||
|
|
|
|
this.url.substr(local.length).startsWith('/notes/') ||
|
|
|
|
this.url.substr(local.length).startsWith('/pages/');
|
2018-02-11 23:35:32 +09:00
|
|
|
return {
|
2019-05-27 18:01:06 +09:00
|
|
|
local,
|
2018-02-11 23:35:32 +09:00
|
|
|
fetching: true,
|
|
|
|
title: null,
|
|
|
|
description: null,
|
|
|
|
thumbnail: null,
|
|
|
|
icon: null,
|
2018-03-19 02:56:35 +09:00
|
|
|
sitename: null,
|
2018-08-23 00:34:35 +09:00
|
|
|
player: {
|
|
|
|
url: null,
|
|
|
|
width: null,
|
|
|
|
height: null
|
|
|
|
},
|
2018-07-26 00:03:32 +09:00
|
|
|
tweetUrl: null,
|
2019-02-28 03:46:37 +09:00
|
|
|
playerEnabled: false,
|
2019-05-27 18:01:06 +09:00
|
|
|
self: isSelf,
|
|
|
|
hasRoute: hasRoute,
|
|
|
|
attr: hasRoute ? 'to' : 'href',
|
|
|
|
target: hasRoute ? null : '_blank'
|
2018-02-11 23:35:32 +09:00
|
|
|
};
|
|
|
|
},
|
2018-08-30 03:32:42 +09:00
|
|
|
|
2018-02-11 23:35:32 +09:00
|
|
|
created() {
|
2019-06-21 15:41:02 +09:00
|
|
|
const requestUrl = new URL(this.url);
|
2018-03-19 02:56:35 +09:00
|
|
|
|
2019-06-21 15:41:02 +09:00
|
|
|
if (this.detail && requestUrl.hostname == 'twitter.com' && /^\/.+\/status(es)?\/\d+/.test(requestUrl.pathname)) {
|
|
|
|
this.tweetUrl = requestUrl;
|
2018-07-26 00:03:32 +09:00
|
|
|
const twttr = (window as any).twttr || {};
|
|
|
|
const loadTweet = () => twttr.widgets.load(this.$refs.tweet);
|
|
|
|
|
|
|
|
if (twttr.widgets) {
|
|
|
|
Vue.nextTick(loadTweet);
|
|
|
|
} else {
|
|
|
|
const wjsId = 'twitter-wjs';
|
|
|
|
if (!document.getElementById(wjsId)) {
|
|
|
|
const head = document.getElementsByTagName('head')[0];
|
|
|
|
const script = document.createElement('script');
|
|
|
|
script.setAttribute('id', wjsId);
|
|
|
|
script.setAttribute('src', 'https://platform.twitter.com/widgets.js');
|
|
|
|
head.appendChild(script);
|
|
|
|
}
|
|
|
|
twttr.ready = loadTweet;
|
|
|
|
(window as any).twttr = twttr;
|
|
|
|
}
|
2018-08-09 04:21:25 +09:00
|
|
|
return;
|
|
|
|
}
|
2018-08-30 03:32:42 +09:00
|
|
|
|
2019-06-21 15:41:02 +09:00
|
|
|
if (requestUrl.hostname === 'music.youtube.com') {
|
|
|
|
requestUrl.hostname = 'youtube.com';
|
|
|
|
}
|
|
|
|
|
|
|
|
const requestLang = (lang || 'ja-JP').replace('ja-KS', 'ja-JP');
|
|
|
|
|
|
|
|
requestUrl.hash = '';
|
2018-12-12 21:19:52 +09:00
|
|
|
|
2019-06-21 15:41:02 +09:00
|
|
|
fetch(`/url?url=${encodeURIComponent(requestUrl.href)}&lang=${requestLang}`).then(res => {
|
2018-08-09 04:21:25 +09:00
|
|
|
res.json().then(info => {
|
2018-08-30 03:32:42 +09:00
|
|
|
if (info.url == null) return;
|
|
|
|
this.title = info.title;
|
|
|
|
this.description = info.description;
|
|
|
|
this.thumbnail = info.thumbnail;
|
|
|
|
this.icon = info.icon;
|
|
|
|
this.sitename = info.sitename;
|
|
|
|
this.fetching = false;
|
2019-02-28 03:46:37 +09:00
|
|
|
this.player = info.player;
|
2018-08-30 03:32:42 +09:00
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
2018-02-11 23:35:32 +09:00
|
|
|
});
|
2018-02-05 14:25:19 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="stylus" scoped>
|
2018-08-23 16:25:36 +09:00
|
|
|
.player
|
2018-08-23 00:34:35 +09:00
|
|
|
position relative
|
2018-03-19 02:56:35 +09:00
|
|
|
width 100%
|
|
|
|
|
2019-03-12 13:12:34 +09:00
|
|
|
> button
|
|
|
|
position absolute
|
|
|
|
top -1.5em
|
|
|
|
right 0
|
|
|
|
font-size 1em
|
|
|
|
width 1.5em
|
|
|
|
height 1.5em
|
|
|
|
padding 0
|
|
|
|
margin 0
|
|
|
|
color var(--text)
|
|
|
|
background rgba(128, 128, 128, 0.2)
|
|
|
|
opacity 0.7
|
|
|
|
|
|
|
|
&:hover
|
|
|
|
opacity 0.9
|
|
|
|
|
2018-08-23 00:34:35 +09:00
|
|
|
> iframe
|
|
|
|
height 100%
|
|
|
|
left 0
|
|
|
|
position absolute
|
|
|
|
top 0
|
|
|
|
width 100%
|
|
|
|
|
2018-09-27 22:50:34 +09:00
|
|
|
.mk-url-preview
|
2018-04-22 19:33:06 +09:00
|
|
|
> a
|
|
|
|
display block
|
2018-05-28 14:59:55 +09:00
|
|
|
font-size 14px
|
2018-12-30 14:00:57 +09:00
|
|
|
border solid var(--lineWidth) var(--urlPreviewBorder)
|
2018-04-22 19:33:06 +09:00
|
|
|
border-radius 4px
|
|
|
|
overflow hidden
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
&:hover
|
|
|
|
text-decoration none
|
2018-09-27 22:50:34 +09:00
|
|
|
border-color var(--urlPreviewBorderHover)
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> article > header > h1
|
|
|
|
text-decoration underline
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> .thumbnail
|
|
|
|
position absolute
|
|
|
|
width 100px
|
|
|
|
height 100%
|
|
|
|
background-position center
|
|
|
|
background-size cover
|
2019-02-28 03:46:37 +09:00
|
|
|
display flex
|
|
|
|
justify-content center
|
|
|
|
align-items center
|
|
|
|
|
|
|
|
> button
|
|
|
|
font-size 3.5em
|
|
|
|
opacity: 0.7
|
|
|
|
|
|
|
|
&:hover
|
|
|
|
font-size 4em
|
|
|
|
opacity 0.9
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
& + article
|
|
|
|
left 100px
|
|
|
|
width calc(100% - 100px)
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> article
|
|
|
|
padding 16px
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> header
|
|
|
|
margin-bottom 8px
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> h1
|
|
|
|
margin 0
|
|
|
|
font-size 1em
|
2018-09-27 22:50:34 +09:00
|
|
|
color var(--urlPreviewTitle)
|
2018-02-11 23:35:32 +09:00
|
|
|
|
|
|
|
> p
|
|
|
|
margin 0
|
2018-09-27 22:50:34 +09:00
|
|
|
color var(--urlPreviewText)
|
2018-02-11 23:35:32 +09:00
|
|
|
font-size 0.8em
|
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> footer
|
|
|
|
margin-top 8px
|
|
|
|
height 16px
|
2018-02-11 23:35:32 +09:00
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
> img
|
|
|
|
display inline-block
|
|
|
|
width 16px
|
|
|
|
height 16px
|
|
|
|
margin-right 4px
|
|
|
|
vertical-align top
|
|
|
|
|
|
|
|
> p
|
|
|
|
display inline-block
|
|
|
|
margin 0
|
2018-09-27 22:50:34 +09:00
|
|
|
color var(--urlPreviewInfo)
|
2018-04-22 19:33:06 +09:00
|
|
|
font-size 0.8em
|
|
|
|
line-height 16px
|
|
|
|
vertical-align top
|
|
|
|
|
2018-05-17 23:18:24 +09:00
|
|
|
@media (max-width 700px)
|
|
|
|
> .thumbnail
|
|
|
|
position relative
|
|
|
|
width 100%
|
|
|
|
height 100px
|
|
|
|
|
|
|
|
& + article
|
|
|
|
left 0
|
|
|
|
width 100%
|
2019-02-28 03:57:35 +09:00
|
|
|
|
2018-05-28 14:59:55 +09:00
|
|
|
@media (max-width 550px)
|
|
|
|
font-size 12px
|
|
|
|
|
|
|
|
> .thumbnail
|
|
|
|
height 80px
|
|
|
|
|
|
|
|
> article
|
|
|
|
padding 12px
|
|
|
|
|
2018-04-22 19:33:06 +09:00
|
|
|
@media (max-width 500px)
|
2018-05-28 14:59:55 +09:00
|
|
|
font-size 10px
|
2018-04-22 19:33:06 +09:00
|
|
|
|
|
|
|
> .thumbnail
|
2018-05-17 23:18:24 +09:00
|
|
|
height 70px
|
2018-04-22 19:33:06 +09:00
|
|
|
|
|
|
|
> article
|
|
|
|
padding 8px
|
2018-02-05 14:25:19 +09:00
|
|
|
|
2018-05-28 14:59:55 +09:00
|
|
|
> header
|
|
|
|
margin-bottom 4px
|
|
|
|
|
|
|
|
> footer
|
|
|
|
margin-top 4px
|
|
|
|
|
|
|
|
> img
|
|
|
|
width 12px
|
|
|
|
height 12px
|
|
|
|
|
2019-01-06 12:56:13 +09:00
|
|
|
&.compact
|
|
|
|
> .thumbnail
|
|
|
|
position: absolute
|
|
|
|
width 56px
|
|
|
|
height 100%
|
|
|
|
|
|
|
|
> article
|
|
|
|
left 56px
|
|
|
|
width calc(100% - 56px)
|
|
|
|
padding 4px
|
|
|
|
|
|
|
|
> header
|
|
|
|
margin-bottom 2px
|
|
|
|
|
|
|
|
> footer
|
|
|
|
margin-top 2px
|
|
|
|
|
2018-09-01 13:08:43 +09:00
|
|
|
&.mini
|
|
|
|
font-size 10px
|
|
|
|
|
|
|
|
> .thumbnail
|
|
|
|
position relative
|
|
|
|
width 100%
|
|
|
|
height 60px
|
|
|
|
|
|
|
|
> article
|
|
|
|
left 0
|
|
|
|
width 100%
|
|
|
|
padding 8px
|
|
|
|
|
|
|
|
> header
|
|
|
|
margin-bottom 4px
|
|
|
|
|
|
|
|
> footer
|
|
|
|
margin-top 4px
|
|
|
|
|
|
|
|
> img
|
|
|
|
width 12px
|
|
|
|
height 12px
|
|
|
|
|
2019-01-06 12:56:13 +09:00
|
|
|
&.compact
|
|
|
|
> .thumbnail
|
2019-02-25 19:45:00 +09:00
|
|
|
position absolute
|
2019-01-06 12:56:13 +09:00
|
|
|
width 56px
|
|
|
|
height 100%
|
|
|
|
|
|
|
|
> article
|
|
|
|
left 56px
|
|
|
|
width calc(100% - 56px)
|
|
|
|
padding 4px
|
|
|
|
|
|
|
|
> header
|
|
|
|
margin-bottom 2px
|
|
|
|
|
|
|
|
> footer
|
|
|
|
margin-top 2px
|
|
|
|
|
|
|
|
&.compact
|
|
|
|
> article
|
|
|
|
> header h1, p, footer
|
2019-02-25 19:45:00 +09:00
|
|
|
overflow hidden
|
|
|
|
white-space nowrap
|
|
|
|
text-overflow ellipsis
|
2018-02-05 14:25:19 +09:00
|
|
|
</style>
|