Display page by default instead of post
Closed this issue · 3 comments
charles-hood commented
Is there a way I can display a static page, for example the About page, in the right content pane, by default, upon first entering the site? (Instead of posts)
alxshelepenok commented
You can edit the indexTemplate as in the example below:
import React from "react";
import { graphql } from "gatsby";
import { Layout } from "@/components/Layout";
import { Meta } from "@/components/Meta";
import { Page } from "@/components/Page";
import { Sidebar } from "@/components/Sidebar";
import { useSiteMetadata } from "@/hooks";
import { Node } from "@/types";
interface Props {
data: {
markdownRemark: Node;
};
}
const PageTemplate: React.FC<Props> = ({ data }: Props) => {
const { html: body } = data.markdownRemark;
const { frontmatter } = data.markdownRemark;
const { title } = frontmatter;
return (
<Layout>
<Sidebar />
<Page title={title}>
<div dangerouslySetInnerHTML={{ __html: body }} />
</Page>
</Layout>
);
};
export const query = graphql`
query PageTemplate {
markdownRemark(frontmatter: { template: { eq: "index" } }) {
id
html
frontmatter {
title
date
description
socialImage {
publicURL
}
}
}
}
`;
export const Head: React.FC<Props> = ({ data }) => {
const { title, subtitle, url } = useSiteMetadata();
const {
frontmatter: {
title: pageTitle,
description: pageDescription = "",
socialImage,
},
} = data.markdownRemark;
const description = pageDescription || subtitle;
const image = socialImage?.publicURL && url.concat(socialImage?.publicURL);
return (
<Meta
title={`${pageTitle} - ${title}`}
description={description}
image={image}
/>
);
};
export default PageTemplate;
And then just create an md file with the content for that page. It is important that template
be index
.
---
title: "Home page"
template: "index"
---
Hello World
charles-hood commented
Where should the index md file be located and what should it be named?
I'm getting:
NOT FOUND
You just hit a route that doesn't exist... the sadness.
alxshelepenok commented
Must be inside the content
directory.