0.0.46 • Published 1 year ago

@fy-/head v0.0.46

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@fy-/head

Simple head manager for Vue3/Vite (supports SSR) inspired by @vueuse/head.

Install

npm i @fy-/head

Load Vue Plugin

import {
    createFyHead
} from '@fy-/head';
export const createApp = async (isSSR = false) => {
    //...
    const fyhead = createFyHead();
    app.use(fyhead);
    //...
    return {
        app,
        router,
        head: fyhead,
        pinia
    };
};

Usage

import {
    useFyHead
} from '@fy-/head';

// Simple
useFyHead({
    title: computed(() =>
        computedRoute.value.meta.title ? computedRoute.value.meta.title : 'fyvue'
    ),
    metas: [{
            property: 'og:type',
            content: 'website',
        },
        {
            property: 'og:image',
            content: 'https://fy-vue.com/fyvue.png',
        },
        {
            name: 'twitter:image',
            content: 'https://fy-vue.com/fyvue.png',
        },
    ],
});

// Script example
useFyHead({
    scripts: [{
        src: 'https://js.stripe.com/v3',
        id: 'stripe-script',
    }, ],
});

// Fully reactive example (in this example "seo" is a Ref)
useFyHead({
    title: computed(() => seo.value.title),
    links: computed(() => {
        const _res: Array < any > = [];

        if (initial && getMode() == 'ssr') {
            _res.push({
                rel: 'canonical',
                href: `${getUrl().scheme}://${getUrl().host}${getUrl().path}`,
                key: 'canonical',
            });
        }
        if (seo.value.prev) {
            _res.push({
                rel: 'prev',
                href: seo.value.prev,
                key: 'prev',
            });
        }
        if (seo.value.next) {
            _res.push({
                rel: 'next',
                href: seo.value.next,
                key: 'next',
            });
        }
        return _res;
    }),
    //...
});

SSR Example

async function handleSSR(
    createApp: Function,
    cb: Function,
    options: SSROptions = {}
) {
    const {
        app,
        router,
        head,
        pinia
    } = await createApp(true);
    //...
    const {
        headTags,
        htmlAttrs,
        bodyAttrs,
        bodyTags
    } = head.renderHeadToString();
    //... (fyhead onlysupports headTags for now, htmlAttrs,bodyAttrs & bodyTags are empty for now.
}
0.0.41

1 year ago

0.0.42

1 year ago

0.0.43

1 year ago

0.0.44

1 year ago

0.0.45

1 year ago

0.0.46

1 year ago

0.0.40

1 year ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.36

2 years ago

0.0.37

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.31

3 years ago

0.0.30

3 years ago

0.0.29

3 years ago

0.0.28

3 years ago

0.0.27

3 years ago

0.0.26

3 years ago

0.0.25

3 years ago

0.0.22

3 years ago

0.0.21

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.1

3 years ago

0.0.1-alpha.3

3 years ago

0.0.1-alpha.2

3 years ago

0.0.1-alpha.1

3 years ago