misskey-awawa/src/client/app/common/views/components/url-preview.vue

150 lines
2.7 KiB
Vue
Raw Normal View History

2018-02-05 05:25:19 +00:00
<template>
2018-03-18 17:56:35 +00:00
<iframe v-if="youtubeId" type="text/html" height="250"
2018-03-18 18:46:13 +00:00
:src="`https://www.youtube.com/embed/${youtubeId}?origin=${misskeyUrl}`"
2018-03-18 17:56:35 +00:00
frameborder="0"/>
2018-04-22 10:33:06 +00:00
<div v-else class="mk-url-preview">
<a :href="url" target="_blank" :title="url" v-if="!fetching">
2018-03-18 17:56:35 +00:00
<div class="thumbnail" v-if="thumbnail" :style="`background-image: url(${thumbnail})`"></div>
<article>
<header>
<h1>{{ title }}</h1>
</header>
<p>{{ description }}</p>
<footer>
<img class="icon" v-if="icon" :src="icon"/>
<p>{{ sitename }}</p>
</footer>
</article>
</a>
</div>
2018-02-05 05:25:19 +00:00
</template>
2018-02-11 14:35:32 +00:00
<script lang="ts">
import Vue from 'vue';
2018-03-18 18:20:10 +00:00
import { url as misskeyUrl } from '../../../config';
2018-02-11 14:35:32 +00:00
export default Vue.extend({
props: ['url'],
data() {
return {
fetching: true,
title: null,
description: null,
thumbnail: null,
icon: null,
2018-03-18 17:56:35 +00:00
sitename: null,
2018-03-18 18:20:10 +00:00
youtubeId: null,
misskeyUrl
2018-02-11 14:35:32 +00:00
};
},
created() {
2018-03-18 17:56:35 +00:00
const url = new URL(this.url);
if (url.hostname == 'www.youtube.com') {
this.youtubeId = url.searchParams.get('v');
} else if (url.hostname == 'youtu.be') {
this.youtubeId = url.pathname;
} else {
2018-05-09 11:14:34 +00:00
fetch('/url?url=' + encodeURIComponent(this.url)).then(res => {
2018-03-18 17:56:35 +00:00
res.json().then(info => {
this.title = info.title;
this.description = info.description;
this.thumbnail = info.thumbnail;
this.icon = info.icon;
this.sitename = info.sitename;
this.fetching = false;
});
2018-02-05 05:25:19 +00:00
});
2018-03-18 17:56:35 +00:00
}
2018-02-11 14:35:32 +00:00
}
});
2018-02-05 05:25:19 +00:00
</script>
<style lang="stylus" scoped>
2018-03-18 17:56:35 +00:00
iframe
width 100%
2018-04-21 10:05:55 +00:00
root(isDark)
2018-04-22 10:33:06 +00:00
> a
display block
font-size 16px
border solid 1px isDark ? #191b1f : #eee
border-radius 4px
overflow hidden
2018-02-11 14:35:32 +00:00
2018-04-22 10:33:06 +00:00
&:hover
text-decoration none
border-color isDark ? #4f5561 : #ddd
2018-02-11 14:35:32 +00:00
2018-04-22 10:33:06 +00:00
> article > header > h1
text-decoration underline
2018-02-11 14:35:32 +00:00
2018-04-22 10:33:06 +00:00
> .thumbnail
position absolute
width 100px
height 100%
background-position center
background-size cover
2018-02-11 14:35:32 +00:00
2018-04-22 10:33:06 +00:00
& + article
left 100px
width calc(100% - 100px)
2018-02-11 14:35:32 +00:00
2018-04-22 10:33:06 +00:00
> article
padding 16px
2018-02-11 14:35:32 +00:00
2018-04-22 10:33:06 +00:00
> header
margin-bottom 8px
2018-02-11 14:35:32 +00:00
2018-04-22 10:33:06 +00:00
> h1
margin 0
font-size 1em
color isDark ? #d6dae0 : #555
2018-02-11 14:35:32 +00:00
> p
margin 0
2018-04-22 10:33:06 +00:00
color isDark ? #a4aab3 : #777
2018-02-11 14:35:32 +00:00
font-size 0.8em
2018-04-22 10:33:06 +00:00
> footer
margin-top 8px
height 16px
2018-02-11 14:35:32 +00:00
2018-04-22 10:33:06 +00:00
> img
display inline-block
width 16px
height 16px
margin-right 4px
vertical-align top
> p
display inline-block
margin 0
color isDark ? #b0b4bf : #666
font-size 0.8em
line-height 16px
vertical-align top
@media (max-width 500px)
font-size 8px
border none
> .thumbnail
width 70px
& + article
left 70px
width calc(100% - 70px)
> article
padding 8px
2018-02-05 05:25:19 +00:00
2018-04-21 10:05:55 +00:00
.mk-url-preview[data-darkmode]
root(true)
.mk-url-preview:not([data-darkmode])
root(false)
2018-02-05 05:25:19 +00:00
</style>