Skip to content

refacto: moved title meta tag in pages #278

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

Merged
merged 3 commits into from
Mar 24, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 0 additions & 7 deletions templates/next/components/foo/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { FunctionComponent, useState } from "react";
import Link from "next/link";
import { useRouter } from "next/router";
import Head from "next/head";
import { ErrorMessage, Formik } from "formik";
import { fetch } from "../../utils/dataAccess";
import { {{{ucf}}} } from '../../types/{{{ucf}}}';
Expand All @@ -28,12 +27,6 @@ export const Form: FunctionComponent<Props> = ({ {{{lc}}} }) => {

return (
<div>
<div>
<Head>
<title>{ {{{lc}}} ? `Edit {{{ucf}}} ${ {{~lc}}['@id']}` : `Create {{{ucf}}}` }</title>
<meta property="og:title" content={ {{{lc}}} ? `Edit {{{ucf}}} ${ {{~lc}}['@id']}` : `Create {{{ucf}}}` } />
</Head>
</div>
<h1>{ {{{lc}}} ? `Edit {{{ucf}}} ${ {{~lc}}['@id']}` : `Create {{{ucf}}}` }</h1>
<Formik
initialValues={ {{~lc}} ? {...{{lc~}} } : new {{{ucf}}}()}
Expand Down
7 changes: 0 additions & 7 deletions templates/next/components/foo/List.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FunctionComponent } from "react";
import Link from "next/link";
import Head from "next/head";
import ReferenceLinks from "../../components/common/ReferenceLinks";
import { {{{ucf}}} } from '../../types/{{{ucf}}}';

Expand All @@ -10,12 +9,6 @@ interface Props {

export const List: FunctionComponent<Props> = ({ {{{name}}} }) => (
<div>
<div>
<Head>
<title>{{{ucf}}} List</title>
<meta property="og:title" content="{{{ucf}}} List" key="title" />
</Head>
</div>
<h1>{{{ucf}}} List</h1>
<Link href="/{{{name}}}/create">
<a className="btn btn-primary">Create</a>
Expand Down
7 changes: 0 additions & 7 deletions templates/next/components/foo/Show.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { FunctionComponent, useState } from 'react';
import Link from 'next/link';
import Head from "next/head";
import { useRouter } from "next/router";
import { fetch } from "../../utils/dataAccess";
import { ReferenceLinks } from '../common/ReferenceLinks';
Expand Down Expand Up @@ -28,12 +27,6 @@ export const Show: FunctionComponent<Props> = ({ {{{lc}}} }) => {

return (
<div>
<div>
<Head>
<title>{`Show {{{ucf}}} ${ {{~lc}}['@id']}`}</title>
<meta property="og:title" content={`Show {{{ucf}}} ${ {{~lc}}['@id']}`} key="title" />
</Head>
</div>
<h1>{`Show {{{ucf}}} ${ {{~lc}}['@id']}`}</h1>
<table className="table table-responsive table-striped table-hover">
<thead>
Expand Down
12 changes: 10 additions & 2 deletions templates/next/pages/foos/[id]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ import { NextComponentType, NextPageContext } from 'next';
import { Form } from '../../../components/{{{lc}}}/Form';
import { {{{ucf}}} } from '../../../types/{{{ucf}}}';
import { fetch } from '../../../utils/dataAccess';
import Head from "next/head";

interface Props {
{{{lc}}}: {{{ucf}}};
};

const Page: NextComponentType<NextPageContext, Props, Props> = ({ {{{lc}}} }) => {

return (
<Form {{{lc}}}={ {{{lc}}} }/>
<div>
<div>
<Head>
<title>{ {{{lc}}} && `Edit {{{ucf}}} ${ {{~lc}}['@id']}`}</title>
<meta property="og:title" content={ {{{lc}}} && `Edit{{{ucf}}} ${ {{~lc}}['@id']}`} key="title" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary if the content is the same as the <title> tag?

Copy link
Contributor Author

@justinezahiri justinezahiri Mar 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the <title> tag is used by Google and meta property="og:title" is used by social medias.
(see: https://www.quora.com/In-terms-of-SEO-value-does-the-Open-Graph-meta-title-tag-meta-property-og-title-have-as-much-value-as-a-Title-tag-Can-we-leave-title-tag-out, it's an old thread but maybe still valid, see NextJS documentation examples about <Head /> component : https://nextjs.org/docs/api-reference/next/head)

</Head>
</div>
<Form {{{lc}}}={ {{{lc}}} }/>
</div>
);
};

Expand Down
11 changes: 10 additions & 1 deletion templates/next/pages/foos/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@ import { NextComponentType, NextPageContext } from 'next';
import { Show } from '../../../components/{{{lc}}}/Show';
import { {{{ucf}}} } from '../../../types/{{{ucf}}}';
import { fetch } from '../../../utils/dataAccess';
import Head from "next/head";

interface Props {
{{{lc}}}: {{{ucf}}};
};

const Page: NextComponentType<NextPageContext, Props, Props> = ({ {{{lc}}} }) => {
return (
<Show {{{lc}}}={ {{{lc}}} }/>
<div>
<div>
<Head>
<title>{`Show {{{ucf}}} ${ {{~lc}}['@id']}`}</title>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<title>{`Show {{{ucf}}} ${ {{~lc}}['@id']}`}</title>
<title>{`Show {{{ucf}}} ${ {{~lc}}['@id']}`}</title>

<meta property="og:title" content={`Show {{{ucf}}} ${ {{~lc}}['@id']}`} key="title" />
</Head>
</div>
<Show {{{lc}}}={ {{{lc}}} }/>
</div>
);
};

Expand Down
14 changes: 13 additions & 1 deletion templates/next/pages/foos/create.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { NextComponentType, NextPageContext } from "next";
import { Form } from "../../components/{{{lc}}}/Form";
import Head from "next/head";

const Page: NextComponentType<NextPageContext> = () => (
<div>
<div>
<Head>
<title>Create {{{ucf}}} </title>
<meta property="og:title" content="Create {{{ucf}}}" key="title" />
</Head>
</div>
<Form />
</div>
)

const Page: NextComponentType<NextPageContext> = () => <Form />;

export default Page;
11 changes: 10 additions & 1 deletion templates/next/pages/foos/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ import { List } from '../../components/{{{lc}}}/List';
import { PagedCollection } from '../../types/Collection';
import { {{{ucf}}} } from '../../types/{{{ucf}}}';
import { fetch } from '../../utils/dataAccess';
import Head from "next/head";

interface Props {
collection: PagedCollection<{{{ucf}}}>;
}

const Page: NextComponentType<NextPageContext, Props, Props> = ({collection}) => (
<List {{{name}}}={collection['{{{hydraPrefix}}}member']}/>
<div>
<div>
<Head>
<title>{{{ucf}}} List</title>
<meta property="og:title" content="{{{ucf}}} List" key="title" />
</Head>
</div>
<List {{{name}}}={collection['{{{hydraPrefix}}}member']}/>
</div>
);

Page.getInitialProps = async () => {
Expand Down