Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve status image quality #391

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cab3ed4
feat: improve status image quality
Shinigami92 Dec 10, 2022
4e81d0e
improve
Shinigami92 Dec 10, 2022
5607c2f
update lastUsed
Shinigami92 Dec 11, 2022
32e68b6
Merge branch 'main' into feat-increase-status-preview-card-image-quality
Shinigami92 Dec 11, 2022
f73219f
Merge branch 'main' into feat-increase-status-preview-card-image-quality
Shinigami92 Dec 12, 2022
19c8393
use cache via nuxt config
Shinigami92 Dec 12, 2022
2a819c6
iterate
Shinigami92 Dec 12, 2022
2c3e025
Only call opengraph if needed
Shinigami92 Dec 12, 2022
a4eae98
Only request opengraph if api key is defined
Shinigami92 Dec 12, 2022
bd0a251
fallback to hybridGraph
Shinigami92 Dec 12, 2022
b90479d
testing
Shinigami92 Dec 12, 2022
0f19373
use routeRules cache
Shinigami92 Dec 12, 2022
a34e7e2
Add opengraph types
Shinigami92 Dec 12, 2022
26bc4e7
more safe
Shinigami92 Dec 12, 2022
2f72c03
pass url as path variable
Shinigami92 Dec 12, 2022
ed091d2
use srcset
Shinigami92 Dec 12, 2022
dff937a
use new glob
Shinigami92 Dec 12, 2022
cfacff8
remove log
Shinigami92 Dec 12, 2022
5da564d
fix comment
Shinigami92 Dec 12, 2022
49290b7
Merge branch 'main' into feat-increase-status-preview-card-image-quality
Shinigami92 Dec 12, 2022
5e717ca
fix fallbackUrl
Shinigami92 Dec 12, 2022
e88d255
refactor: use runtimeConfig
danielroe Dec 12, 2022
797b99f
refactor: only enable maxAge locally
danielroe Dec 12, 2022
bb013dd
fix: expand og:image regexp
danielroe Dec 12, 2022
174b2b2
throw 404
Shinigami92 Dec 12, 2022
a650b1f
reject http urls
Shinigami92 Dec 12, 2022
eab2342
use 404
Shinigami92 Dec 12, 2022
49a9291
Merge branch 'main' into feat-increase-status-preview-card-image-quality
Shinigami92 Dec 12, 2022
27c0c4d
try sendError
Shinigami92 Dec 12, 2022
200bc3d
use sendError for other 4xx errors
Shinigami92 Dec 12, 2022
e18443a
fallback on error
Shinigami92 Dec 12, 2022
705ce6a
refactor: try fetching images (for netlify cache)
danielroe Dec 12, 2022
83a4ee7
refactor: remove extra computed
danielroe Dec 12, 2022
7b97381
refactor: remove opengraph implementation for now
danielroe Dec 12, 2022
5b37047
refactor: simplify handler and remove opengraph section
danielroe Dec 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ NUXT_STORAGE_DRIVER=
NUXT_STORAGE_FS_BASE=

NUXT_PUBLIC_DISABLE_VERSION_CHECK=

NUXT_OPENGRAPH_API=
5 changes: 4 additions & 1 deletion components/common/CommonBlurhash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default defineComponent({
required: false,
},
},
setup(props, { attrs }) {
setup(props, { attrs, emit }) {
const placeholderSrc = ref<string>()
const isLoaded = ref(false)

Expand All @@ -26,6 +26,9 @@ export default defineComponent({
img.onload = () => {
isLoaded.value = true
}
img.onerror = (ev) => {
emit('onerror', ev)
}
img.src = props.src
if (props.srcset)
img.srcset = props.srcset
Expand Down
15 changes: 12 additions & 3 deletions components/status/StatusPreviewCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ const props = defineProps<{
/** When it is root card in the list, not appear as a child card */
root?: boolean
}>()
const cardImage = $computed(() => props.card.image)
const alt = $computed(() => `${props.card.title} - ${props.card.title}`)
const isSquare = $computed(() => props.smallPictureOnly || props.card.width === props.card.height)
const providerName = $computed(() => props.card.providerName ? props.card.providerName : new URL(props.card.url).hostname)
const useFallback = ref(false)
const imageSrcset = $computed(() => props.card.image
? `${props.card.image}${useFallback.value ? '' : `, /api/og-image/${encodeURIComponent(props.card.url)} 2x`}`
: '',
)

// TODO: handle card.type: 'photo' | 'video' | 'rich';
</script>
Expand All @@ -29,7 +35,7 @@ const providerName = $computed(() => props.card.providerName ? props.card.provid
target="_blank"
>
<div
v-if="card.image"
v-if="cardImage"
flex flex-col
display-block of-hidden
border="base"
Expand All @@ -41,11 +47,14 @@ const providerName = $computed(() => props.card.providerName ? props.card.provid
>
<CommonBlurhash
:blurhash="card.blurhash"
:src="card.image"
:src="cardImage"
:srcset="imageSrcset"
:width="card.width"
:height="card.height"
:alt="alt"
w-full h-full object-cover
w-full
h-full object-cover
@onerror="useFallback = true"
/>
</div>
<div
Expand Down
9 changes: 9 additions & 0 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default defineNuxtConfig({
namespaceId: '',
apiToken: '',
},
opengraphApi: '',
public: {
env: isCI ? isPreview ? 'staging' : 'production' : 'local',
translateApi: '',
Expand All @@ -86,6 +87,14 @@ export default defineNuxtConfig({
crawlLinks: false,
routes: ['/', '/200.html'],
},
routeRules: {
'/api/og-image/**': {
static: isCI,
cache: !isCI
? { maxAge: 86400 } // 1 day
: {},
},
},
},
app: {
keepalive: true,
Expand Down
21 changes: 21 additions & 0 deletions opengraph-io.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// TODO @Shinigami92 2022-12-12: @Shinigami92 might add @types/opengraph-io to DefinitelyTyped
// Or directly to the repo

declare module 'opengraph-io' {
function opengraph(options: {
appId: string
fullRender?: boolean
}): {
getSiteInfo(url: string): Promise<{
hybridGraph: {
image: string
},
openGraph: {
image: {
url: string
}
}
}>
}
export = opengraph
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"lru-cache": "^7.14.1",
"masto": "^4.7.5",
"nuxt": "^3.0.0",
"opengraph-io": "~2.0.0",
"pinia": "^2.0.27",
"postcss-nested": "^6.0.0",
"prettier": "^2.8.0",
Expand Down
Loading