Add posts and old grade-calc
Fix small bugs >bad commit
This commit is contained in:
		
							
								
								
									
										42
									
								
								pages/posts/[page].tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								pages/posts/[page].tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,42 @@
 | 
			
		||||
import Layout from '../../components/layout';
 | 
			
		||||
import { useRouter } from 'next/router';
 | 
			
		||||
import { getAllPosts, getPost } from '../../lib/slug';
 | 
			
		||||
import ReactMarkdown from 'react-markdown';
 | 
			
		||||
import Image from 'next/image';
 | 
			
		||||
 | 
			
		||||
function Post({post} : any) { // eh
 | 
			
		||||
    const router = useRouter();
 | 
			
		||||
    return (
 | 
			
		||||
        <Layout name={post.title} title={post.title} ancestors={[{name:'Posts', path: 'posts'}]}>
 | 
			
		||||
            <section className='block'>
 | 
			
		||||
                {post.cover ? <Image width={640} height={360} layout="intrinsic" src={`/assets/images/${post.cover}`} alt={`${post.title} Cover Image`} /> : ''}
 | 
			
		||||
                <ReactMarkdown>{post.content}</ReactMarkdown>
 | 
			
		||||
            </section>
 | 
			
		||||
        </Layout>
 | 
			
		||||
    );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function getStaticProps({params}: any) {
 | 
			
		||||
    const post = getPost(params.page);
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
        props: {post}
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function getStaticPaths() {
 | 
			
		||||
    const posts = getAllPosts();
 | 
			
		||||
    return {
 | 
			
		||||
        paths: posts.map(post => {
 | 
			
		||||
            return {
 | 
			
		||||
                params: {
 | 
			
		||||
                    page: post.slug
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }),
 | 
			
		||||
        fallback: false
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
export default Post;
 | 
			
		||||
							
								
								
									
										32
									
								
								pages/posts/index.tsx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								pages/posts/index.tsx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,32 @@
 | 
			
		||||
import Link from 'next/link';
 | 
			
		||||
import React from 'react';
 | 
			
		||||
import Layout from '../../components/layout';
 | 
			
		||||
import { getAllPosts } from '../../lib/slug';
 | 
			
		||||
import Pages from '../../public/pages.json';
 | 
			
		||||
import cachePostLinkData from '../../util/post-cache';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
function HomePage({posts}: any) {
 | 
			
		||||
    Pages.sort((x, y) => { return ('' + x.title).localeCompare(y.title) });
 | 
			
		||||
    return (
 | 
			
		||||
        <Layout name='Posts'>
 | 
			
		||||
            {posts.map((post: any) => {
 | 
			
		||||
                return <section key='' className='h5 block'>
 | 
			
		||||
                    <Link href={`posts/${post.slug}`}>
 | 
			
		||||
                        {post.title}
 | 
			
		||||
                    </Link>
 | 
			
		||||
                    <div>[{ (new Date(post.last_updated)).toLocaleString()}]</div>
 | 
			
		||||
                </section>
 | 
			
		||||
            })}
 | 
			
		||||
        </Layout>
 | 
			
		||||
    )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export async function getStaticProps() {
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
        props: {posts: cachePostLinkData()}
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default HomePage;
 | 
			
		||||
		Reference in New Issue
	
	Block a user