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(core): better SEO for images and package playground #92

Merged
merged 24 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
40603d6
feat(core): created playground
ojvribeiro Nov 8, 2022
b8a32ce
chore(deps): bumped `laravel-mix-simple-image-processing` to `v1.0.8`
ojvribeiro Nov 8, 2022
c1602a2
refactor(core): removed Sass functions
ojvribeiro Nov 8, 2022
83367db
fix(core): replaced path with alias
ojvribeiro Nov 8, 2022
dfcc6da
feat(welcome): replaced logo with newer version
ojvribeiro Nov 8, 2022
415b2c3
chore(deps): bumped `laravel-mix-simple-image-processing` to `v1.0.10`
ojvribeiro Nov 16, 2022
80719a0
wip: trying some `mix.imgs` fonfigs
ojvribeiro Nov 16, 2022
da21cd6
refactor(core): removed unused code
ojvribeiro Nov 16, 2022
8e1b02e
removed unused code
ojvribeiro Nov 16, 2022
2676939
wip(core): refactored Image component
ojvribeiro Nov 16, 2022
4de1075
Merge branch 'main' into fix-image-lighthouse
ojvribeiro Nov 17, 2022
a25d341
Merge branch 'main' into fix-image-lighthouse
ojvribeiro Nov 18, 2022
736c628
fix(core): fixed `imgs` options and some paths
ojvribeiro Nov 21, 2022
b946052
chore(core): removed console.log
ojvribeiro Nov 21, 2022
a8a623f
fix(core/image): fixed default `alt` and `title`
ojvribeiro Nov 21, 2022
48a7e1b
fix(core/image): reduced the placeholder image size
ojvribeiro Nov 21, 2022
eed21c7
fix(core): renamed `data-app` to `data-vulmix-app`
ojvribeiro Nov 21, 2022
e2eaf8f
Update index.ejs
ojvribeiro Nov 21, 2022
cfda156
refactor(core/image): reduced Image component scope
ojvribeiro Nov 21, 2022
17edf65
feat(core/demo): added demo placeholder images
ojvribeiro Nov 21, 2022
5175860
chore(demo): reset demo
ojvribeiro Dec 4, 2022
1444e49
fix(core): makes the `assets/img` folder optional
ojvribeiro Dec 4, 2022
f8c767f
fix(core): makes the `assets/img` folder optional
ojvribeiro Dec 4, 2022
de35a4c
fix(core): fixed path
ojvribeiro Dec 4, 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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
node_modules
package-lock.json
yarn.lock
demo
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.github
webpack.mix.js
demo
2 changes: 2 additions & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
_dist
3 changes: 3 additions & 0 deletions demo/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<VulmixWelcome />
</template>
Binary file added demo/assets/icons/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions demo/assets/icons/vulmix.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions demo/assets/sass/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
html,
body {
height: 100%;
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "mix watch --hot",
"prod": "mix --production",
"serve": "npx http-server -p 8000 -a localhost _dist --gzip --proxy http://localhost:8000?"
"serve": "npx http-server -p 8000 -a localhost demo/_dist --gzip --proxy http://localhost:8000?"
},
"author": "Victor Ribeiro",
"license": "MIT",
Expand Down
6 changes: 0 additions & 6 deletions src/assets/sass/utils/_functions.scss

This file was deleted.

1 change: 0 additions & 1 deletion src/assets/sass/utils/index.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
@import "mixins";
@import "functions";
62 changes: 17 additions & 45 deletions src/components/Image.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
<template>
<img
:src="imgSrc"
:alt="props.alt"
:title="props.title"
:alt="props.alt ? props.alt : ''"
:title="props.title ? props.title : ''"
:loading="targetIsVisible ? 'eager' : 'lazy'"
ref="imageEl"
/>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useElementSize, useElementVisibility } from '@vueuse/core'
import { useElementVisibility } from '@vueuse/core'

const props = defineProps({
src: {
type: String,
default: '',
},
width: {
type: String,
},
height: {
type: String,
},
alt: {
type: String,
default: 'Image',
Expand All @@ -35,57 +29,35 @@
type: String,
default: 'true',
},
original: {
type: String,
default: 'false',
},
})

const imageEl = ref(null)
const imgSrc = ref(props.src)

const { width, height } = useElementSize(imageEl)
const targetIsVisible = useElementVisibility(imageEl)

const _image = new Image()
_image.src = props.src.replace(
/\/assets\/img\/(|.*)([a-zA-Z0-9_-])\.(png|jpg|jpeg|gif)$/i,
`/assets/img/$1$2@50.${props.webp === 'true' ? 'webp' : '$3'}`
`/assets/img/$1$2.${props.webp === 'true' ? 'webp' : '$3'}`
)

imgSrc.value = _image.src

onMounted(() => {
function replace(size) {
_image.onload = function () {
if (props.original === 'false') {
imgSrc.value = props.src.replace(
/\/assets\/img\/(|.*)([a-zA-Z0-9_-])\.(png|jpg|jpeg|gif)$/i,
`/assets/img/$1$2@${size}.${
props.webp === 'true' ? 'webp' : '$3'
}`
)
} else {
imgSrc.value = props.src.replace(
/\/assets\/img\/(|.*)([a-zA-Z0-9_-])\.(png|jpg|jpeg|gif)$/i,
`/assets/img/$1$2.${
props.webp === 'true' ? 'webp' : '$3'
}`
)
}
}
}

if (imageEl.value.width < 300) {
replace('300')
} else if (imageEl.value.width >= 300 && imageEl.value.width < 600) {
replace('600')
} else if (imageEl.value.width >= 601 && imageEl.value.width < 900) {
replace('900')
} else if (imageEl.value.width >= 901 && imageEl.value.width < 1200) {
replace('1200')
} else {
replace('1920')
_image.onload = function () {
imgSrc.value = props.src.replace(
/\/assets\/img\/(|.*)([a-zA-Z0-9_-])\.(png|jpg|jpeg|gif)$/i,
`/assets/img/$1$2.${props.webp === 'true' ? 'webp' : '$3'}`
)
}
})
</script>

<style scoped>
img {
display: block;
max-width: 100%;
height: auto;
}
</style>
Loading