2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
2022-05-28 07:28:12 +02:00
|
|
|
<MkContainer :show-header="widgetProps.showHeader" class="mkw-rss">
|
2022-12-19 11:01:30 +01:00
|
|
|
<template #header><i class="ti ti-rss"></i>RSS</template>
|
|
|
|
<template #func><button class="_button" @click="configure"><i class="ti ti-settings"></i></button></template>
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-07-11 03:13:11 +02:00
|
|
|
<div class="ekmkgxbj">
|
2020-10-17 13:12:00 +02:00
|
|
|
<MkLoading v-if="fetching"/>
|
2021-11-19 11:36:12 +01:00
|
|
|
<div v-else class="feed">
|
2022-06-30 16:45:11 +02:00
|
|
|
<a v-for="item in items" class="item" :href="item.link" rel="nofollow noopener" target="_blank" :title="item.title">{{ item.title }}</a>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
2020-07-11 03:13:11 +02:00
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</MkContainer>
|
2020-01-29 20:37:25 +01:00
|
|
|
</template>
|
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, onUnmounted, ref, watch } from 'vue';
|
|
|
|
import { useWidgetPropsManager, Widget, WidgetComponentEmits, WidgetComponentExpose, WidgetComponentProps } from './widget';
|
2022-06-25 20:12:58 +02:00
|
|
|
import { GetFormResultType } from '@/scripts/form';
|
2021-11-11 18:02:25 +01:00
|
|
|
import * as os from '@/os';
|
2022-09-06 11:21:49 +02:00
|
|
|
import MkContainer from '@/components/MkContainer.vue';
|
2022-06-25 20:12:58 +02:00
|
|
|
import { useInterval } from '@/scripts/use-interval';
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const name = 'rss';
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-01-08 12:30:01 +01:00
|
|
|
const widgetPropsDef = {
|
|
|
|
url: {
|
|
|
|
type: 'string' as const,
|
|
|
|
default: 'http://feeds.afpbb.com/rss/afpbb/afpbbnews',
|
2020-01-29 20:37:25 +01:00
|
|
|
},
|
2022-06-30 16:45:11 +02:00
|
|
|
showHeader: {
|
|
|
|
type: 'boolean' as const,
|
|
|
|
default: true,
|
|
|
|
},
|
2022-01-08 12:30:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
type WidgetProps = GetFormResultType<typeof widgetPropsDef>;
|
|
|
|
|
|
|
|
// 現時点ではvueの制限によりimportしたtypeをジェネリックに渡せない
|
|
|
|
//const props = defineProps<WidgetComponentProps<WidgetProps>>();
|
|
|
|
//const emit = defineEmits<WidgetComponentEmits<WidgetProps>>();
|
|
|
|
const props = defineProps<{ widget?: Widget<WidgetProps>; }>();
|
2022-05-25 09:43:12 +02:00
|
|
|
const emit = defineEmits<{ (ev: 'updateProps', props: WidgetProps); }>();
|
2022-01-08 12:30:01 +01:00
|
|
|
|
|
|
|
const { widgetProps, configure } = useWidgetPropsManager(name,
|
|
|
|
widgetPropsDef,
|
|
|
|
props,
|
|
|
|
emit,
|
|
|
|
);
|
|
|
|
|
|
|
|
const items = ref([]);
|
|
|
|
const fetching = ref(true);
|
|
|
|
|
|
|
|
const tick = () => {
|
2022-12-03 11:42:05 +01:00
|
|
|
window.fetch(`/api/fetch-rss?url=${widgetProps.url}`, {}).then(res => {
|
2022-01-08 12:30:01 +01:00
|
|
|
res.json().then(feed => {
|
|
|
|
items.value = feed.items;
|
|
|
|
fetching.value = false;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
watch(() => widgetProps.url, tick);
|
|
|
|
|
2022-06-25 20:12:58 +02:00
|
|
|
useInterval(tick, 60000, {
|
|
|
|
immediate: true,
|
|
|
|
afterMounted: true,
|
2022-01-08 12:30:01 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose<WidgetComponentExpose>({
|
|
|
|
name,
|
|
|
|
configure,
|
|
|
|
id: props.widget ? props.widget.id : null,
|
2020-01-29 20:37:25 +01:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
2022-12-27 10:01:06 +01:00
|
|
|
<style lang="scss">
|
2020-01-29 20:37:25 +01:00
|
|
|
.ekmkgxbj {
|
|
|
|
> .feed {
|
|
|
|
padding: 0;
|
|
|
|
font-size: 0.9em;
|
|
|
|
|
2022-06-30 16:45:11 +02:00
|
|
|
> .item {
|
2020-01-29 20:37:25 +01:00
|
|
|
display: block;
|
|
|
|
padding: 8px 16px;
|
2020-10-27 10:11:41 +01:00
|
|
|
color: var(--fg);
|
2020-01-29 20:37:25 +01:00
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
2021-03-02 14:57:16 +01:00
|
|
|
overflow: hidden;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
|
|
|
&:nth-child(even) {
|
|
|
|
background: rgba(#000, 0.05);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|