Comments (1)
--{{Alt text fix
Most of this code was copied into jhthms Bulma after I installed it. It was from my original site based on:
https://github.com/calebanthony/gridsome-bulma
https://calebanthony.github.io/gridsome-bulma/
I now have custom Alt text working for all images on the site!
Here's how I did it (look for lines with "<-- added" and "<-- changed").
These are excerpts, not complete files:
/home/loren/gridsome_2023/src/pages/Index.vue
---
<page-query>
query {
posts: allPost {
edges {
node {
id
title
path
tags {
id
title
path
}
date(format: "D MMMM YYYY")
timeToRead
description
cover_image(width: 770, fit: inside, blur: 10)
... on Post {
id
title
alt <-- added
path
}
}
}
}
}
</page-query>
---
/home/loren/gridsome_2023/src/templates/Post.vue
---
<template>
<Layout>
<div class="has-text-centered">
<h1 class="title is-1">
{{ $page.post.title }}
</h1>
<PostMeta
class="subtitle is-size-6"
:post="$page.post"
/>
</div>
<div class="has-text-centered">
<g-image
:alt="$page.post.alt" <-- changed
:src="$page.post.cover_image"
/>
</div>
... AND:
<page-query>
query Post($path: String!) {
post: post(path: $path) {
title
alt <-- added
path
date(format: "D MMMM YYYY")
timeToRead
tags {
id
title
path
}
description
content
cover_image(width: 770, fit: inside, blur: 1)
}
}
</page-query>
---
/home/loren/gridsome_2023/src/components/PostCard.vue
---
<template>
<div class="card">
<g-link
v-if="post.cover_image"
class="card-image"
:to="post.path"
>
<figure class="image">
<g-image
:alt="post.alt" <-- changed
:src="post.cover_image"
/>
</figure>
</g-link>
<div class="card-content">
<g-link
:to="post.path"
class="width-770 is-size-4 has-text-weight-bold"
>
{{ post.title }}
</g-link>
<p
class="content"
v-html="post.description"
/>
<PostMeta :post="post" />
</div>
<div
v-if="post.tags"
class="card-footer"
>
<PostTags
class="card-footer-item"
:post="post"
/>
</div>
</div>
</template>
---
Warnings:
Some of those changes require exiting Develop and restarting it.
Some browsers may not notice the changes when the site is loaded from a server on the external web, even though the local Develop mode worked properly. A page Reload may help, Force Reload may help, but you may have to delete all cached information from the browser to see the changes properly! Or try a browser that has never visited the external URL...
I even saw some browsers with history of visiting the URL fail to lazy load the sharp versions of the images, leaving the blurred versions visible, or on a cellular connection fail to load any version of some images.
Hope this helps someone...
from gridsome.
Related Issues (20)
- Dynamic pages using templates HOT 1
- error while using gridsome/vue-remark
- Load content within content container
- Gridsome i18n dynamic router with dot doesnt work HOT 1
- Gridsome is not really static and titles don't work when refreshing HOT 1
- Create a section that doesnt reload when you switch from page
- gridsome build stuck HOT 2
- how to use @gridsome/transformer-remark to marked
- An error which says "Failed to process image xxxx" happened when run gridsome build
- Google Analytics 4? HOT 1
- Will Gridsome continue to have support and updates? Or will it become a deprecated technology? HOT 4
- Gridsome build stucked
- Building with dynamically generated pages for tags fails.
- Google Tag Manager tag is not firing when viewing the page; we have to reload the page. HOT 1
- [remark-wiki-link] Warning: please upgrade to remark 13 to use this plugin
- Gridsome build error HOT 1
- Gridsome airtable requires update as API key will be depricated from Feb 2024
- Is there a way to merge grid some into nuxt?
- Build error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gridsome.