Skip to content

Commit f56454f

Browse files
Json ld response (#298)
* json ld resp using resp.text * added missing files in NextGenerator.js file * fixed response name in getServerSideProps * use reponse.text for json-ld * try to use response.text
1 parent c7a92fe commit f56454f

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

templates/next/components/foo/Show.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useRouter } from "next/router";
44
import { fetch } from "../../utils/dataAccess";
55
import ReferenceLinks from '../common/ReferenceLinks';
66
import { {{{ucf}}} } from '../../types/{{{ucf}}}';
7+
import Head from 'next/head'
78

89
interface Props {
910
{{{lc}}}: {{{ucf}}};
@@ -27,6 +28,14 @@ export const Show: FunctionComponent<Props> = ({ {{{lc}}} }) => {
2728

2829
return (
2930
<div>
31+
<Head>
32+
<title>{`Show {{{ucf}}} ${ {{~lc}}['@id']}`}</title>
33+
<script
34+
type="application/ld+json"
35+
>
36+
{text}
37+
</script>
38+
</Head>
3039
<h1>{`Show {{{ucf}}} ${ {{~lc}}['@id']}`}</h1>
3140
<table className="table table-responsive table-striped table-hover">
3241
<thead>

templates/next/pages/foos/[id]/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const Page: NextComponentType<NextPageContext, Props, Props> = (props) => {
2525
<title>{`Show {{{ucf}}} ${ {{~lc}}['@id'] }`}</title>
2626
</Head>
2727
</div>
28-
<Show {{{lc}}}={ {{{lc}}} } />
28+
<Show {{{lc}}}={ {{{lc}}} } text={ props.text } />
2929
</div>
3030
);
3131
};
@@ -36,6 +36,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
3636
return {
3737
props: {
3838
{{{lc}}}: response.data,
39+
text: response.text,
3940
hubURL: response.hubURL,
4041
},
4142
revalidate: 1,

templates/next/utils/dataAccess.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface Violation {
1212
}
1313

1414
const extractHubURL = (response: Response): null | URL => {
15-
const linkHeader = response.headers.get('Link');
15+
const linkHeader = response.headers.get("Link");
1616
if (!linkHeader) return null;
1717

1818
const matches = linkHeader.match(
@@ -41,6 +41,7 @@ export const fetch = async (id: string, init: RequestInit = {}) => {
4141
return {
4242
hubURL: extractHubURL(resp)?.toString(), // URL cannot be serialized as JSON, must be sent as string
4343
data: normalize(json),
44+
text: await resp.text(),
4445
};
4546
}
4647

0 commit comments

Comments
 (0)