Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
3.6 kB
2
Indexable
Never
import {
    basePath,
    domainApp,
    HREFLANG_BY_CLIENT,
    pathname as pathnameConst,
    productionEnv,
    uhfEnv,
} from "@services/constant";
import Head from "next/head";
import React from "react";
import { useRouter } from "next/router";
import NextHeadProptypes from "./NextHead.propstypes";
const NextHead = ({ config, image, preloadLinks }) => {
    const router = useRouter();
    const pathname = config?.url?.substring(6, config.url.length) || "";
    return (
        <Head>
            <meta charSet="utf-8" />
            <title key="title">{config.title}</title>
            <meta
                key="robots"
                name="robots"
                content={`${
                    uhfEnv === productionEnv
                        ? "index,follow"
                        : "noindex,nofollow"
                }`}
            />
            <meta
                name="viewport"
                content="initial-scale=1.0, width=device-width"
            />
            <link
                rel="canonical"
                href={domainApp + config.canonical}
                key="canonical"
            />
            ,
            <meta key="og:title" property="og:title" content={config.title} />
            <meta
                key="twitter:title"
                property="twitter:title"
                content={config.ogTitle ? config.ogTitle : config.title}
            />
            <meta
                key="description"
                name="description"
                content={config.description}
            />
            <meta
                key="og:description"
                property="og:description"
                content={config.description}
            />
            <meta
                key="twitter:description"
                name="twitter:description"
                content={config.description}
            />
            <meta key="twitter:site" name="twitter:site" content="@airasia" />
            <meta key="twitter:card" name="twitter:card" content="summary" />
            <meta
                key="og:url"
                property="og:url"
                content={domainApp + config.url || domainApp + config.canonical}
            />
            <meta key="keywords" name="keywords" content={config.keywords} />
            <meta key={`og:image`} property="og:image" content={image} />
            <meta key="twitter:image" name="twitter:image" content={image} />
            <meta key="og:type" property="og:type" content={`website`} />
            <link rel="manifest" href="/static/manifest/manifest.json" />
            {router.pathname === pathnameConst.HOME_PAGE &&
                HREFLANG_BY_CLIENT?.map(({ hrefLang, url }) => {
                    return (
                        <link
                            rel="alternate"
                            key={`languageAlternate-${hrefLang}`}
                            hrefLang={hrefLang}
                            href={domainApp + url + (pathname ? pathname : "")}
                        />
                    );
                })}
            <link
                id="favicon"
                rel="shortcut icon"
                href={`${basePath}/images/favicon.ico`}
                type="image/png"
            />
            {preloadLinks &&
                preloadLinks.map((link, i) => (
                    <link key={i} rel="preload" as="image" href={link} />
                ))}
        </Head>
    );
};

NextHead.propTypes = NextHeadProptypes.PropTypes;
NextHead.defaultProps = NextHeadProptypes.default;

export default NextHead;