Skip to content

Commit

Permalink
Merge pull request #33 from zernonia/change-api-to-syndication
Browse files Browse the repository at this point in the history
Use Twitter's Syndication to extract content
  • Loading branch information
zernonia authored Jun 8, 2022
2 parents 3758289 + d7e65ba commit 96181c4
Show file tree
Hide file tree
Showing 19 changed files with 988 additions and 299 deletions.
62 changes: 62 additions & 0 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,20 @@ useHead({
.tweet-author-info {
margin-left: 1rem;
}
.tweet-author-title {
display: flex;
align-items: center;
}
.tweet-author-name {
line-height: 1rem;
font-weight: 500;
}
.tweet-author-verified {
width: 1.25rem;
height: 1.25rem;
margin-left: 0.25rem;
color: var(--text-secondary);
}
.tweet-author-handler {
line-height: 1.8rem;
color: var(--text-secondary);
Expand All @@ -116,6 +126,58 @@ useHead({
margin: 0 0.05em 0 0.1em;
vertical-align: -0.1em;
}
.tweet-media {
margin-top: 1rem;
border: 1px solid var(--border);
border-radius: 1rem;
overflow: hidden;
}
.tweet-summary {
display: flex;
}
.tweet-summary img {
width: 130px;
height: 130px;
}
.tweet-summary > div {
display: flex;
flex-direction: column;
justify-content: center;
border-left: 1px solid var(--border);
border-top: 0px !important;
}
.tweet-summary-card-text {
border-top: 1px solid var(--border);
padding: 0.75rem;
font-size: 0.95rem;
color: var(--subtext-primary);
}
.tweet-summary-card-text span {
font-size: 0.9rem;
}
.tweet-summary-card-text h2 {
color: var(--text-primary);
}
.tweet-quoted .tweet {
margin-top: 1rem;
width: 100%;
}
.tweet-info {
margin-top: 1rem;
font-size: 0.875rem;
line-height: 1.25rem;
display: flex;
align-items: center;
color: var(--subtext-primary);
}
.tweet-info-favourite {
width: 1.25rem;
height: 1.25rem;
margin-right: 0.5rem;
}
.tweet-info-date {
margin-left: 1rem;
}
[data-style="supabase"] {
width: 400px;
Expand Down
1 change: 1 addition & 0 deletions assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
--bg-primary: white;
--text-primary: rgb(35 35 35);
--text-secondary: rgb(31, 155, 240);
--subtext-primary: rgb(148, 163, 184);
}

body {
Expand Down
10 changes: 6 additions & 4 deletions components/Tweet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ const props = defineProps({
url: String,
layout: { type: String, default: "" },
css: { type: String, default: "" },
show_original_link: { type: Boolean, default: false },
enable_twemoji: { type: Boolean, default: true },
show_media: { type: Boolean, default: false },
show_quoted_tweet: { type: Boolean, default: false },
show_info: { type: Boolean, default: false },
redirect: { type: Boolean, default: true },
})
Expand All @@ -29,14 +31,14 @@ defineExpose({ data })
</script>

<template>
<div class="relative overflow-hidden">
<div class="relative">
<div
class="ring-0 hover:ring-2 ring-light-700 transition rounded-2xl cursor-pointer"
class="ring-0 hover:ring-3 ring-blue-400 transition rounded-2xl cursor-pointer"
@click="onClick"
v-if="data?.html?.length"
v-html="data.html"
></div>
<div v-if="pending" class="absolute top-0 left-0 w-full h-full">
<div v-if="pending" class="absolute top-0 left-0 w-full h-full overflow-hidden">
<div class="tweet !h-full !w-full" :data-style="props.layout">
<div class="flex items-center animate-pulse">
<div class="flex items-center">
Expand Down
39 changes: 39 additions & 0 deletions components/docs/Base.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<script setup lang="ts">
defineProps({
method: String,
url: String,
description: String,
})
</script>

<template>
<div class="mt-20">
<div class="relative flex items-center p-2 bg-light-600 rounded-xl">
<div class="tag bg-blue-500 mr-4">{{ method }}</div>
<div>{{ url }}</div>
<span class="absolute text-sm text-gray-400 right-4 top-full md:top-auto">{{ description }}</span>
</div>

<div class="flex flex-col md:flex-row mt-12 md:space-x-6">
<div class="md:w-1/2 flex flex-col">
<div class="flex flex-col">
<h4 class="text-xl font-semibold mb-4 text-gray-400">Query Params</h4>
<slot name="config"></slot>
</div>

<div class="flex flex-col">
<h4 class="mt-20 text-xl font-semibold mb-4 text-gray-400">Results</h4>
<div class="tag bg-green-500">200</div>

<div class="mt-4">
<slot name="result"></slot>
</div>
</div>
</div>

<div class="min-h-80 md:w-1/2 p-4 md:p-8 mt-4 md:mt-0 rounded-2xl bg-light-600">
<slot name="preview"></slot>
</div>
</div>
</div>
</template>
56 changes: 56 additions & 0 deletions components/docs/DocsTweet.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<script setup lang="ts">
const params = ref({
url: "https://twitter.com/zernonia/status/1524620865987506176",
layout: "",
css: "tailwind",
enable_twemoji: true,
show_media: true,
show_quoted_tweet: true,
show_info: true,
})
const { $hljs } = useNuxtApp()
const tweetRef = ref()
const highlightResponse = computed(() =>
tweetRef.value?.data
? $hljs.highlight(JSON.stringify(tweetRef.value.data, null, " "), { language: "json", ignoreIllegals: false })
.value
: ""
)
</script>

<template>
<DocsBase method="GET" url="https://tweetic.io/api/tweet" description="Obtain static tweets">
<template #config>
<label for="url">url</label>
<input type="text" name="url" id="url" v-model="params.url" />
<label class="mt-2" for="layout">layout <span class="description"> ("" | "supabase")</span></label>
<select v-model="params.layout" name="layout" id="layout">
<option value="">Default</option>
<option value="supabase">Supabase</option>
</select>
<label class="mt-2" for="css">css <span class="description"> ("" | "tailwind")</span></label>
<select v-model="params.css" name="css" id="css">
<option value="">Default CSS</option>
<option value="tailwind">Tailwind</option>
</select>

<Toggle class="mt-2" name="enable_twemoji" v-model="params.enable_twemoji"> enable_twemoji </Toggle>
<Toggle class="mt-2" name="show_media" v-model="params.show_media"> show_media </Toggle>
<Toggle class="mt-2" name="show_quoted_tweet" v-model="params.show_quoted_tweet"> show_quoted_tweet </Toggle>
<Toggle class="mt-2" name="show_info" v-model="params.show_info"> show_info </Toggle>
</template>

<template #result>
<p>html - <span class="description">HTML that are ready to render</span></p>
<p>meta - <span class="description">Meta data from Twitter</span></p>
</template>

<template #preview>
<div class="flex justify-center">
<Tweet ref="tweetRef" v-bind="params"></Tweet>
</div>
<pre class="overflow-x-scroll text-gray-400 mt-4 text-sm" v-html="highlightResponse"></pre>
</template>
</DocsBase>
</template>
24 changes: 0 additions & 24 deletions interface.ts

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"@supabase/supabase-js": "^1.35.3",
"@vueuse/core": "^8.4.2",
"@yeger/vue-masonry-wall": "^3.0.30",
"cheerio": "^1.0.0-rc.11",
"date-fns": "^2.28.0",
"highlight.js": "^11.5.1",
"lodash-es": "^4.17.21",
"node-html-parser": "^5.3.3",
"twemoji": "^14.0.2",
"twitter-api-v2": "^1.12.0",
"vue-toastification": "^2.0.0-rc.5"
Expand Down
17 changes: 11 additions & 6 deletions pages/create.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script setup lang="ts">
import { useStorage } from "@vueuse/core"
import { useClipboard } from "@vueuse/core"
import { obtainCss } from "~~/function"
import { TweetOptions } from "~~/interface"
import { obtainCss } from "~~/utils/function"
import { TweetOptions } from "~~/utils/types"
import { useToast } from "vue-toastification"
const toast = useToast()
Expand All @@ -12,12 +12,15 @@ const tweetsOptions = useStorage<TweetOptions>("tweets-options", {
css: "",
show_original_link: false,
enable_twemoji: true,
show_media: true,
show_quoted_tweet: true,
show_info: true,
})
const exportOptions = useStorage("export-options", {})
const computedInput = computed(() => tweetsInput.value.filter((i) => i != ""))
const getTweetsHTML = () => {
let tweets = document.querySelectorAll(".tweet-container")
let tweets = document.querySelectorAll(".tweet-container > div")
let innerHTMLs = ""
tweets.forEach((i) => {
innerHTMLs += i.innerHTML
Expand Down Expand Up @@ -108,10 +111,12 @@ useCustomHead("Tweetic | Create now!", "Create your own static tweets now!")
<option value="tailwind">TailwindCSS</option>
</select>

<Toggle class="mt-2" name="show_original_link" v-model="tweetsOptions.show_original_link">
Show Original Link
</Toggle>
<Toggle class="mt-2" name="enable_twemoji" v-model="tweetsOptions.enable_twemoji"> Enable Twemoji </Toggle>
<Toggle class="mt-2" name="show_media" v-model="tweetsOptions.show_media"> Show Media </Toggle>
<Toggle class="mt-2" name="show_quoted_tweet" v-model="tweetsOptions.show_quoted_tweet">
Show Quoted Tweet
</Toggle>
<Toggle class="mt-2" name="show_info" v-model="tweetsOptions.show_info"> Show Info </Toggle>
</div>

<div class="mt-20 flex flex-col">
Expand Down
69 changes: 2 additions & 67 deletions pages/docs.vue
Original file line number Diff line number Diff line change
@@ -1,70 +1,5 @@
<script setup lang="ts">
const params = ref({
url: "https://twitter.com/zernonia/status/1524620865987506176",
layout: "supabase",
css: "tailwind",
show_original_link: false,
enable_twemoji: true,
})
const { $hljs } = useNuxtApp()
const tweetRef = ref()
const highlightResponse = computed(() =>
tweetRef.value?.data
? $hljs.highlight(JSON.stringify(tweetRef.value.data, null, " "), { language: "json", ignoreIllegals: false })
.value
: ""
)
</script>

<template>
<div class="mt-20">
<div class="relative flex items-center p-2 bg-light-600 rounded-xl">
<div class="tag bg-blue-500 mr-4">GET</div>
<div>https://tweetic.io/api/tweets</div>
<span class="absolute text-sm text-gray-400 right-4 top-full md:top-auto">Obtain static tweets</span>
</div>

<div class="flex flex-col md:flex-row mt-12 md:space-x-6">
<div class="md:w-1/2 flex flex-col">
<div class="flex flex-col">
<h4 class="text-xl font-semibold mb-4 text-gray-400">Query Params</h4>
<label for="url">url</label>
<input type="text" name="url" id="url" v-model="params.url" />
<label class="mt-2" for="layout">layout <span class="description"> ("" | "supabase")</span></label>
<select v-model="params.layout" name="layout" id="layout">
<option value="">Default</option>
<option value="supabase">Supabase</option>
</select>
<label class="mt-2" for="css">css <span class="description"> ("" | "tailwind")</span></label>
<select v-model="params.css" name="css" id="css">
<option value="">Default CSS</option>
<option value="tailwind">Tailwind</option>
</select>

<Toggle class="mt-2" name="show_original_link" v-model="params.show_original_link">
show_original_link
</Toggle>
<Toggle class="mt-2" name="enable_twemoji" v-model="params.enable_twemoji"> enable_twemoji </Toggle>
</div>

<div class="flex flex-col">
<h4 class="mt-20 text-xl font-semibold mb-4 text-gray-400">Results</h4>
<div class="tag bg-green-500">200</div>

<div class="mt-4">
<p>html - <span class="description">HTML that are ready to render</span></p>
<p>oembed - <span class="description">Oembed information from Twitter</span></p>
</div>
</div>
</div>

<div class="min-h-80 md:w-1/2 p-4 md:p-8 mt-4 md:mt-0 rounded-2xl bg-light-600">
<div class="flex justify-center">
<Tweet ref="tweetRef" v-bind="params"></Tweet>
</div>
<pre class="overflow-x-scroll text-gray-400 mt-4 text-sm" v-html="highlightResponse"></pre>
</div>
</div>
<div>
<DocsTweet></DocsTweet>
</div>
</template>
Loading

1 comment on commit 96181c4

@vercel
Copy link

@vercel vercel bot commented on 96181c4 Jun 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.