Skip to content

Commit

Permalink
feat: mock images
Browse files Browse the repository at this point in the history
  • Loading branch information
zyyv committed Sep 29, 2024
1 parent c908e3f commit 00c2ee5
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
12 changes: 6 additions & 6 deletions components/ImgBlurHash.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ function getDataUrlFromArr(arr: Uint8ClampedArray, w: number, h: number) {
}
onMounted(() => {
// Decode the blurhash if available
if (props.blurhash) {
const pixels = decode(props.blurhash, 32, 32)
placeholderSrc.value = getDataUrlFromArr(pixels, 32, 32)
}
// Create a temporary image to check when the image has loaded
const img = document.createElement('img')
img.onload = () => {
Expand All @@ -52,12 +58,6 @@ onMounted(() => {
setTimeout(() => {
isLoaded.value = true
}, 3000)
// Decode the blurhash if available
if (props.blurhash) {
const pixels = decode(props.blurhash, 32, 32)
placeholderSrc.value = getDataUrlFromArr(pixels, 32, 32)
}
})
</script>

Expand Down
1 change: 1 addition & 0 deletions components/nav/NavHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const routes = reactive<Menu[]>([
{ path: '/posts', icon: 'i-ri-blogger-line' },
{ path: '/projects', icon: 'i-ri-dashboard-line' },
{ path: '/talks', icon: 'i-ri-file-ppt-line' },
{ path: '/images', icon: 'i-ri-image-line' },
])
const route = useRoute()
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
},
"dependencies": {
"blurhash": "^2.0.5",
"dayjs": "^1.11.13"
"dayjs": "^1.11.13",
"unsplash-js": "^7.0.19"
},
"devDependencies": {
"@antfu/eslint-config": "3.7.1",
Expand All @@ -45,6 +46,7 @@
"esno": "^4.7.0",
"fs-extra": "^11.2.0",
"lint-staged": "^15.2.10",
"node-fetch": "^3.3.2",
"nuxt": "3.13.2",
"octokit": "^4.0.2",
"postcss-import": "^16.1.0",
Expand Down
2 changes: 0 additions & 2 deletions pages/images.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<script lang="ts" setup>
const { data } = await useFetch('/api/images')
console.log(data.value)
</script>

<template>
Expand Down
57 changes: 57 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 00c2ee5

Please sign in to comment.