Skip to content

Replace useHead with useSeoMeta #1483

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 15 additions & 9 deletions app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@
</template>

<script setup>
useHead({
title: "Index",
titleTemplate: "%s - Nuxt 3 Woocommerce",
meta: [
{ name: "viewport", content: "width=device-width, initial-scale=1" },
useSeoMeta({
title: "Nuxt 3 Woocommerce",
description:
"A modern, fast, and SEO-friendly e-commerce site built with Nuxt 3 and WooCommerce.",
ogTitle: "Nuxt 3 Woocommerce",
ogDescription:
"A modern, fast, and SEO-friendly e-commerce site built with Nuxt 3 and WooCommerce.",
twitterCard: "summary_large_image",
htmlAttrs: {
lang: "en",
},
link: [
{
hid: "description",
name: "description",
content: "Nuxt 3 Woocommerce",
rel: "icon",
type: "image/x-icon",
href: "/favicon.ico",
},
],
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
});
</script>

Expand Down
18 changes: 18 additions & 0 deletions components/Products/ProductsSingleProduct.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ const props = defineProps({
const variables = { id: props.id, slug: props.slug };
const { data } = await useAsyncQuery(GET_SINGLE_PRODUCT_QUERY, variables);

watch(
() => data.value,
(productData) => {
if (productData?.product) {
const { name, description, image } = productData.product;
useSeoMeta({
title: name,
description: stripHTML(description),
ogTitle: name,
ogDescription: stripHTML(description),
ogImage: image?.sourceUrl,
twitterCard: 'summary_large_image',
});
}
},
{ immediate: true },
);

watch(
() => data.value,
(dataValue) => {
Expand Down
5 changes: 0 additions & 5 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ export default defineNuxtConfig({
},
},
app: {
head: {
charset: "utf-8",
viewport: "width=500, initial-scale=1",
meta: [{ name: "description", content: "Nuxt 3 - Woocommerce" }],
},
// global transition
pageTransition: { name: "page", mode: "out-in" },
layoutTransition: { name: "layout", mode: "out-in" },
Expand Down
14 changes: 0 additions & 14 deletions pages/product/[product].vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,4 @@

<script setup>
const route = useRoute();

useHead({
title: route.params.product,
titleTemplate: "%s - Nuxt 3 Woocommerce",
meta: [
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{
hid: "description",
name: "description",
content: "Nuxt 3 Woocommerce",
},
],
link: [{ rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
});
</script>