Fixed lint errors :D

Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
2020-01-05 00:56:27 +01:00
parent e255554262
commit 42b7ef1b2c
16 changed files with 230 additions and 229 deletions

View File

@ -1,12 +1,13 @@
import { NextPageContext } from "next"
import{ Component } from 'react'
import Post from "../../components/Post"
import { NextPageContext } from 'next'
import Head from 'next/head'
import Link from 'next/link'
import { Component } from 'react'
import ReactMarkdown from 'react-markdown'
import Error from "../_error"
import Link from "next/link"
import Head from "next/head"
import config from "../../config"
import Post from '../../components/Post'
import config from '../../config'
import Error from '../_error'
interface Props {
post: Post
@ -17,15 +18,34 @@ interface States {
}
export default class PostPage extends Component<Props, States> {
public static async getInitialProps(context: NextPageContext) {
const { slug } = context.query
if (typeof slug === 'object' || slug === '[slug]') {
return {post: undefined}
}
const post = new Post(slug)
await post.fetch()
return {post}
}
public render() {
return (
<main>
<Head>
<title key="title">{`${this.props.post.title} - ${config.og.title}`}</title>
<meta key="description" name="og:description" content={this.props.post.header.short || this.props.post.header.title}/>
<meta
key="description"
name="og:description"
content={this.props.post.header.short || this.props.post.header.title}
/>
<meta key="og:title" property="og:title" content={`${this.props.post.header.title} - ${config.og.title}`} />
<meta key="og:description" property="og:description" content={this.props.post.header.short || this.props.post.header.title}/>
<meta
key="og:description"
property="og:description"
content={this.props.post.header.short || this.props.post.header.title}
/>
{this.props.post.header.image ? (
<meta key="og:image" property="og:image" content={`${config.domain}${this.props.post.header.image}`}/>
) : undefined}
@ -41,7 +61,7 @@ export default class PostPage extends Component<Props, States> {
<ul>
{this.props.post.header.tags.map((el) => (
<li key={el}>
<Link href="/tag/[tag]" as={'/tag/'+el.toLowerCase()}>
<Link href="/tag/[tag]" as={'/tag/' + el.toLowerCase()}>
<a className="button">{el}</a>
</Link>
</li>
@ -129,12 +149,4 @@ export default class PostPage extends Component<Props, States> {
</main>
)
}
public static async getInitialProps(context: NextPageContext) {
const { slug } = context.query
if (typeof slug === "object" || slug === "[slug]") return {post: undefined}
const post = new Post(slug)
await post.fetch()
return {post}
}
}

View File

@ -1,12 +1,13 @@
import React from 'react'
import App from 'next/app'
import '../styl/styl.styl'
import Layout from '../components/Layout'
import Head from 'next/head'
import React from 'react'
import Layout from '../components/Layout'
import config from '../config'
import '../styl/styl.styl'
class MyApp extends App {
render() {
public render() {
const { Component, pageProps } = this.props
return(

View File

@ -1,17 +1,12 @@
// _document is only rendered on the server side and not on the client side
// Event handlers like onClick can't be added to this file
// ./pages/_document.js
import Document, { Html, Head, Main, NextScript } from 'next/document'
import config from '../config'
import Document, { Head, Html, Main, NextScript } from 'next/document'
class MyDocument extends Document {
static async getInitialProps(ctx) {
public static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}
render() {
public render() {
return (
<Html>
<Head>

View File

@ -1,15 +1,14 @@
import React, { Component } from 'react'
import { NextPageContext } from 'next'
import Head from 'next/head'
import Layout from '../components/Layout'
import React, { Component } from 'react'
interface Props {
statusCode: number
}
const codesTexts = {
404: "Page non trouvé !",
500: "Le serveur n'a pas pu répondre a ta demande :O"
404: 'Page non trouvé !',
500: "Le serveur n'a pas pu répondre a ta demande :O",
}
export default class Error extends Component<Props, {}> {
@ -21,7 +20,7 @@ export default class Error extends Component<Props, {}> {
<title>Pouet :D</title>
</Head>
<div className="errorContainer">
<h1>{statusCode ? statusCode : "404"}</h1>
<h1>{statusCode ? statusCode : '404'}</h1>
<h2>{statusCode ? codesTexts[statusCode] : codesTexts[404]}</h2>
</div>
<style jsx>{`
@ -51,8 +50,8 @@ export default class Error extends Component<Props, {}> {
)
}
getInitialProps = ({ res, err }: NextPageContext) => {
public getInitialProps({ res, err }: NextPageContext) {
const statusCode = res ? res.statusCode : err ? err.statusCode : 404
return { statusCode }
}
}
}

View File

@ -1,57 +1,30 @@
import { Component } from 'react'
import Element from '../components/Element'
import Filters from '../components/Filters'
import { Component } from 'react'
import Post, { PostHeader } from '../components/Post'
interface Props {
userAgent?: string
userAgent?: string
}
interface el extends PostHeader {}
interface States {
elements: el[]
elements: Array<PostHeader>
loaded: boolean
asideHeight: number
categories: string[]
categories: Array<string>
}
// export const config = {amp: 'hybrid'}
let elements: PostHeader[] = []
let elements: Array<PostHeader> = []
export default class Page extends Component<Props, States> {
onQuery = async (query: string, recent: boolean = true) => {
// console.log(`query: ${query}`)
const t= elements.filter(el => {
return el.title.toLowerCase().includes(query.toLowerCase())
})
if (recent) {
t.sort((a, b) => {
return (a.date < b.date) ? 1 : -1
})
} else {
t.sort((a, b) => {
return (a.date > b.date) ? 1 : -1
})
}
this.setState({
elements: t
})
}
onHeight = async (height: number) => {
this.setState({
asideHeight: height
})
}
async componentDidMount() {
public async componentDidMount() {
const posts = await Post.fetchAll()
const header: Array<PostHeader> = []
let cats: Array<string> = []
posts.forEach(el => {
const cats: Array<string> = []
posts.forEach((el) => {
el.fetchSync()
header.push(el.header)
cats.push(...el.header.tags)
@ -64,18 +37,25 @@ export default class Page extends Component<Props, States> {
elements = header
this.setState({
categories: cats.filter((item, pos) => cats.indexOf(item) === pos),
elements: header,
loaded: true,
categories: cats.filter((item, pos) => {return cats.indexOf(item) === pos})
})
}
render() {
public render() {
return (
<main>
<span>
{this.state && this.state.elements && this.state.elements.length !== 0 ? this.state.elements.map((el, index) => (
<Element key={index} link={"/"+el.category.toLowerCase() + "/" + el.id} title={el.title} image={el.image} alt={el.imageAlt} date={el.date || new Date} />
<Element
key={index}
link={`/${el.category.toLowerCase()}/${el.id}`}
title={el.title}
image={el.image}
alt={el.imageAlt}
date={el.date || new Date()}
/>
)) : this.state && this.state.loaded ? (
<div>La recherche n'a rien donnée <span className="emoji">😢</span></div>
) : (
@ -105,7 +85,7 @@ export default class Page extends Component<Props, States> {
justify-content: center;
}
@media (min-width: 820px) and (min-height: ${this.state && this.state.asideHeight ? this.state.asideHeight+100 : 600}px) {
@media (min-width: 820px) and (min-height: ${this.state && this.state.asideHeight ? this.state.asideHeight + 100 : 600}px) {
span {
max-width: calc(100% - 400px);
}
@ -116,7 +96,31 @@ export default class Page extends Component<Props, States> {
}
`}</style>
</main>
)
}
private async onQuery(query: string, recent: boolean = true) {
// console.log(`query: ${query}`)
const t = elements.filter( (el) => {
return el.title.toLowerCase().includes(query.toLowerCase())
})
if (recent) {
t.sort((a, b) => {
return (a.date < b.date) ? 1 : -1
})
} else {
t.sort((a, b) => {
return (a.date > b.date) ? 1 : -1
})
}
this.setState({
elements: t,
})
}
private async onHeight(height: number) {
this.setState({
asideHeight: height,
})
}
}

View File

@ -1,20 +1,18 @@
import { NextPage, NextPageContext } from "next"
import Link from 'next/link'
import Post from "../../components/Post"
import { NextPage, NextPageContext } from 'next'
import Element from '../../components/Element'
import Error from "../_error"
// import posts from '../../posts/pages.json'
// import firstline from 'firstline'
// import 'fs'
import Post from '../../components/Post'
import Error from '../_error'
interface Props {
files: Post[],
files: Array<Post>,
tag: string
}
const PortfolioIndex: NextPage<Props> = (props: Props) => {
const el: JSX.Element[] = []
const el: Array<JSX.Element> = []
for (const post of props.files) {
el.push(
)
@ -31,7 +29,13 @@ const PortfolioIndex: NextPage<Props> = (props: Props) => {
<h2>Tag: {props && props.tag}</h2>
<div>
{props.files.map((post, index) => (
<Element key={index} link={"/"+post.header.category.toLowerCase() + "/" + post.header.id} title={post.header.title} image={post.header.image} date={post.header.date || new Date} />
<Element
key={index}
link={`/${post.header.category.toLowerCase()}/${post.header.id}`}
title={post.header.title}
image={post.header.image}
date={post.header.date || new Date()}
/>
))}
</div>
<style jsx>{`
@ -68,18 +72,24 @@ const PortfolioIndex: NextPage<Props> = (props: Props) => {
PortfolioIndex.getInitialProps = async (context: NextPageContext) => {
const { tag } = context.query
if (typeof tag === "object" || tag === "[tag]") return {files: [], tag: ""}
const arr: Post[] = []
if (typeof tag === 'object' || tag === '[tag]') {
return {files: [], tag: ''}
}
const arr: Array<Post> = []
for (const post of await Post.fetchAll()) {
if (!post.isStarted) await post.fetch()
let tags = []
if (!post.isStarted) {
await post.fetch()
}
const tags = []
for (const tg of post.header.tags) {
tags.push(tg.toLowerCase())
}
if (!tags.includes(tag)) continue
if (!tags.includes(tag)) {
continue
}
arr.push(post)
}
return {files: arr, tag: tag} as Props
return {files: arr, tag} as Props
}
export default PortfolioIndex