[basic-example][m] - remove everything related to multiple pages
This commit is contained in:
parent
74a4f9a8ed
commit
8743f0d572
@ -8,4 +8,4 @@ This is the README.md this project.
|
||||
|
||||
## Vega Lite Line Chart from URL
|
||||
|
||||
<VegaLite spec={ { "$schema": "https://vega.github.io/schema/vega-lite/v5.json", "data": {"url": "data_2.csv"}, "width": 600, "height": 250, "mark": "line", "encoding": { "x": {"field": "Time", "type": "temporal"}, "y": {"field": "Anomaly (deg C)", "type": "quantitative"}, "tooltip": {"field": "Anomaly (deg C)", "type": "quantitative"} } } } />
|
||||
<VegaLite spec={ { "$schema": "https://vega.github.io/schema/vega-lite/v5.json", "data": {"url": "data_2.csv"}, "width": 550, "height": 250, "mark": "line", "encoding": { "x": {"field": "Time", "type": "temporal"}, "y": {"field": "Anomaly (deg C)", "type": "quantitative"}, "tooltip": {"field": "Anomaly (deg C)", "type": "quantitative"} } } } />
|
||||
|
||||
@ -4,14 +4,12 @@ import type { NextRequest } from 'next/server'
|
||||
|
||||
// This function can be marked `async` if using `await` inside
|
||||
export async function middleware(req: NextRequest, res: NextResponse) {
|
||||
const refererPaths = req.headers.get('referer').split('/'); // logs the referer URL to the console
|
||||
const urlPaths = req.nextUrl.pathname.split('/')
|
||||
const datasetName = refererPaths[refererPaths.length - 1]
|
||||
const fileName = urlPaths[urlPaths.length - 1]
|
||||
return NextResponse.rewrite(new URL(`/api/get-data-file?datasetName=${datasetName}&fileName=${fileName}`, req.url))
|
||||
return NextResponse.rewrite(new URL(`/api/get-data-file?fileName=${fileName}`, req.url))
|
||||
}
|
||||
|
||||
// See "Matching Paths" below to learn more
|
||||
export const config = {
|
||||
matcher: '/datasets/:file*.csv',
|
||||
matcher: ['/:file*.csv'],
|
||||
}
|
||||
|
||||
@ -7,11 +7,13 @@ export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse<string>
|
||||
) {
|
||||
const contentDir = path.join(process.cwd(), '/content');
|
||||
const datasets = await fs.readdir(contentDir);
|
||||
const query = req.query;
|
||||
const { datasetName, fileName } = query;
|
||||
const { fileName } = query;
|
||||
const dataFile = path.join(
|
||||
process.cwd(),
|
||||
'/content/' + datasetName + '/' + fileName
|
||||
'/content/' + datasets[0] + '/' + fileName
|
||||
);
|
||||
const data = await fs.readFile(dataFile, 'utf8');
|
||||
res.status(200).send(data)
|
||||
|
||||
@ -1,57 +0,0 @@
|
||||
import { promises as fs } from 'fs';
|
||||
import { GetStaticProps } from 'next';
|
||||
import path from 'path';
|
||||
import parse from '../../lib/markdown';
|
||||
import DRD from '../../components/DRD';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const contentDir = path.join(process.cwd(), '/content');
|
||||
const datasets = await fs.readdir(contentDir);
|
||||
return {
|
||||
paths: datasets.map((dataset) => ({ params: { datasetId: dataset } })),
|
||||
fallback: false, // can also be true or 'blocking'
|
||||
};
|
||||
}
|
||||
|
||||
export const getStaticProps: GetStaticProps = async (context) => {
|
||||
const { datasetId } = context.params;
|
||||
const jsonDirectory = path.join(
|
||||
process.cwd(),
|
||||
'/content/' + datasetId + '/README.md'
|
||||
);
|
||||
const readme = await fs.readFile(jsonDirectory, 'utf8');
|
||||
let { mdxSource, frontMatter, excerpt } = await parse(readme, '.mdx');
|
||||
console.log(mdxSource, frontMatter, excerpt)
|
||||
return {
|
||||
props: {
|
||||
mdxSource,
|
||||
frontMatter,
|
||||
excerpt,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default function DatasetPage({ mdxSource, frontMatter, excerpt }) {
|
||||
return (
|
||||
<div className="prose mx-auto">
|
||||
<header>
|
||||
<div className="mb-6">
|
||||
<>
|
||||
<h1>{frontMatter.title}</h1>
|
||||
{frontMatter.author && (
|
||||
<div className="-mt-6">
|
||||
<p className="opacity-60 pl-1">{frontMatter.author}</p>
|
||||
</div>
|
||||
)}
|
||||
{frontMatter.description && (
|
||||
<p className="description">{frontMatter.description}</p>
|
||||
)}
|
||||
</>
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
<DRD source={mdxSource} />
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@ -1,71 +1,48 @@
|
||||
import Head from 'next/head'
|
||||
import Image from 'next/image'
|
||||
import styles from '../styles/Home.module.css'
|
||||
import { GetStaticProps } from 'next';
|
||||
import { promises as fs } from 'fs';
|
||||
import path from 'path';
|
||||
import parse from '../lib/markdown';
|
||||
import DRD from '../components/DRD';
|
||||
|
||||
export default function Home() {
|
||||
export const getStaticProps: GetStaticProps = async (context) => {
|
||||
const contentDir = path.join(process.cwd(), '/content');
|
||||
const datasets = await fs.readdir(contentDir);
|
||||
const datasetReadme = path.join(
|
||||
process.cwd(),
|
||||
'/content/' + datasets[0] + '/README.md'
|
||||
);
|
||||
const readme = await fs.readFile(datasetReadme, 'utf8');
|
||||
let { mdxSource, frontMatter, excerpt } = await parse(readme, '.mdx');
|
||||
return {
|
||||
props: {
|
||||
mdxSource,
|
||||
frontMatter,
|
||||
excerpt,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default function DatasetPage({ mdxSource, frontMatter, excerpt }) {
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<Head>
|
||||
<title>Create Next App</title>
|
||||
<meta name="description" content="Generated by create next app" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
</Head>
|
||||
|
||||
<main className={styles.main}>
|
||||
<h1 className={styles.title}>
|
||||
Welcome to <a href="https://nextjs.org">Next.js!</a>
|
||||
</h1>
|
||||
|
||||
<p className={styles.description}>
|
||||
Get started by editing{' '}
|
||||
<code className={styles.code}>pages/index.tsx</code>
|
||||
</p>
|
||||
|
||||
<div className={styles.grid}>
|
||||
<a href="https://nextjs.org/docs" className={styles.card}>
|
||||
<h2>Documentation →</h2>
|
||||
<p>Find in-depth information about Next.js features and API.</p>
|
||||
</a>
|
||||
|
||||
<a href="https://nextjs.org/learn" className={styles.card}>
|
||||
<h2>Learn →</h2>
|
||||
<p>Learn about Next.js in an interactive course with quizzes!</p>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://github.com/vercel/next.js/tree/canary/examples"
|
||||
className={styles.card}
|
||||
>
|
||||
<h2>Examples →</h2>
|
||||
<p>Discover and deploy boilerplate example Next.js projects.</p>
|
||||
</a>
|
||||
|
||||
<a
|
||||
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={styles.card}
|
||||
>
|
||||
<h2>Deploy →</h2>
|
||||
<p>
|
||||
Instantly deploy your Next.js site to a public URL with Vercel.
|
||||
</p>
|
||||
</a>
|
||||
<div className="prose mx-auto">
|
||||
<header>
|
||||
<div className="mb-6">
|
||||
<>
|
||||
<h1>{frontMatter.title}</h1>
|
||||
{frontMatter.author && (
|
||||
<div className="-mt-6">
|
||||
<p className="opacity-60 pl-1">{frontMatter.author}</p>
|
||||
</div>
|
||||
)}
|
||||
{frontMatter.description && (
|
||||
<p className="description">{frontMatter.description}</p>
|
||||
)}
|
||||
</>
|
||||
</div>
|
||||
</header>
|
||||
<main>
|
||||
<DRD source={mdxSource} />
|
||||
</main>
|
||||
|
||||
<footer className={styles.footer}>
|
||||
<a
|
||||
href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Powered by{' '}
|
||||
<span className={styles.logo}>
|
||||
<Image src="/vercel.svg" alt="Vercel Logo" width={72} height={16} />
|
||||
</span>
|
||||
</a>
|
||||
</footer>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user