mirror of
https://github.com/dzeiocom/markblog.git
synced 2025-04-22 10:52:12 +00:00
Fixed lint errors :D
Signed-off-by: Avior <florian.bouillon@delta-wings.net>
This commit is contained in:
parent
e255554262
commit
42b7ef1b2c
@ -1,7 +1,6 @@
|
|||||||
import React from 'react'
|
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import React from 'react'
|
||||||
import { ChevronRight } from 'react-feather'
|
import { ChevronRight } from 'react-feather'
|
||||||
import next from 'next'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title: string
|
title: string
|
||||||
@ -12,7 +11,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const months = [
|
const months = [
|
||||||
"le 13eme mois",
|
'le 13eme mois',
|
||||||
'Janvier',
|
'Janvier',
|
||||||
'Février',
|
'Février',
|
||||||
'Mars',
|
'Mars',
|
||||||
@ -24,16 +23,13 @@ const months = [
|
|||||||
'Septembre',
|
'Septembre',
|
||||||
'Octobre',
|
'Octobre',
|
||||||
'Novembre',
|
'Novembre',
|
||||||
'Décembre'
|
'Décembre',
|
||||||
]
|
]
|
||||||
|
|
||||||
export default class Element extends React.Component<Props, {}> {
|
export default class Element extends React.Component<Props, {}> {
|
||||||
constructor(props: Props) {
|
public render() {
|
||||||
super(props)
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
let date = this.props.date
|
let date = this.props.date
|
||||||
if (typeof this.props.date === "string") {
|
if (typeof this.props.date === 'string') {
|
||||||
date = new Date(this.props.date)
|
date = new Date(this.props.date)
|
||||||
}
|
}
|
||||||
const t = `${date.getDate()} ${months[date.getMonth()]} ${date.getFullYear()}`
|
const t = `${date.getDate()} ${months[date.getMonth()]} ${date.getFullYear()}`
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import React from 'react'
|
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
import '../styl/styl.styl'
|
import React from 'react'
|
||||||
import { ChevronRight, ChevronDown } from 'react-feather'
|
import { ChevronDown, ChevronRight } from 'react-feather'
|
||||||
|
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
|
import '../styl/styl.styl'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
categories?: string[]
|
categories?: Array<string>
|
||||||
onQuery?: (query: string, sort?: boolean) => void
|
onQuery?: (query: string, sort?: boolean) => void
|
||||||
onHeight?: (height: number) => void
|
onHeight?: (height: number) => void
|
||||||
}
|
}
|
||||||
@ -17,40 +18,9 @@ interface States {
|
|||||||
|
|
||||||
export default class Filters extends React.Component<Props, States> {
|
export default class Filters extends React.Component<Props, States> {
|
||||||
|
|
||||||
private aside = undefined
|
|
||||||
private input = undefined
|
private input = undefined
|
||||||
|
|
||||||
constructor(props: Props) {
|
public render() {
|
||||||
super(props)
|
|
||||||
}
|
|
||||||
|
|
||||||
setInput = element => {
|
|
||||||
this.input = element
|
|
||||||
}
|
|
||||||
|
|
||||||
onKeyDown = (ev: React.KeyboardEvent<HTMLInputElement>) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
this.submit()
|
|
||||||
}, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
onClick = () => {
|
|
||||||
if (this.input.value !== "") {
|
|
||||||
this.submit()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.input.focus()
|
|
||||||
}
|
|
||||||
|
|
||||||
onChange = (ev) => {
|
|
||||||
this.submit(ev.target.value === "true")
|
|
||||||
}
|
|
||||||
|
|
||||||
submit = (sort?: boolean) => {
|
|
||||||
if (this.props.onQuery) this.props.onQuery(this.input.value, sort)
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
return (
|
||||||
<aside>
|
<aside>
|
||||||
<div>Trier</div>
|
<div>Trier</div>
|
||||||
@ -72,14 +42,13 @@ export default class Filters extends React.Component<Props, States> {
|
|||||||
</div>
|
</div>
|
||||||
<p>Languages :</p>
|
<p>Languages :</p>
|
||||||
<span>
|
<span>
|
||||||
{this.props.categories.map(cat => (
|
{this.props.categories.map((cat) => (
|
||||||
<Link key={cat} href="/tag/[tag]" as={`/tag/${cat.toLowerCase()}`}>
|
<Link key={cat} href="/tag/[tag]" as={`/tag/${cat.toLowerCase()}`}>
|
||||||
<a className="button">{cat}</a>
|
<a className="button">{cat}</a>
|
||||||
</Link>
|
</Link>
|
||||||
))}
|
))}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|
||||||
<style jsx>{`
|
<style jsx>{`
|
||||||
|
|
||||||
aside {
|
aside {
|
||||||
@ -123,4 +92,32 @@ export default class Filters extends React.Component<Props, States> {
|
|||||||
</aside>
|
</aside>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setInput = (element) => {
|
||||||
|
this.input = element
|
||||||
|
}
|
||||||
|
|
||||||
|
private onKeyDown = (ev: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.submit()
|
||||||
|
}, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
private onClick = () => {
|
||||||
|
if (this.input.value !== '') {
|
||||||
|
this.submit()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.input.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
private onChange = (ev) => {
|
||||||
|
this.submit(ev.target.value === 'true')
|
||||||
|
}
|
||||||
|
|
||||||
|
private submit = (sort?: boolean) => {
|
||||||
|
if (this.props.onQuery) {
|
||||||
|
this.props.onQuery(this.input.value, sort)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,10 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { PhoneCall, Mail, GitHub, Twitter, Linkedin } from 'react-feather'
|
import { GitHub, Linkedin, Mail, PhoneCall, Twitter } from 'react-feather'
|
||||||
import Link from 'next/link'
|
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
|
|
||||||
interface Props {}
|
export default class Footer extends React.Component<{}, {}> {
|
||||||
|
public render() {
|
||||||
interface States {}
|
|
||||||
|
|
||||||
export default class Footer extends React.Component<Props, States> {
|
|
||||||
constructor(props: Props) {
|
|
||||||
super(props)
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
return (
|
return (
|
||||||
<footer>
|
<footer>
|
||||||
<div className="pre"></div>
|
<div className="pre"></div>
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
|
|
||||||
interface Props {
|
export default class Header extends React.Component<{}, {}> {
|
||||||
}
|
public render() {
|
||||||
|
|
||||||
export default class Header extends React.Component<Props, {}> {
|
|
||||||
constructor(props: Props) {
|
|
||||||
super(props)
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{/* <p>Bienvenue sur le Portfolio de Florian BOUILLON !</p> */}
|
{/* <p>Bienvenue sur le Portfolio de Florian BOUILLON !</p> */}
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import Navbar from './Navbar'
|
|
||||||
import Menu from './Menu'
|
|
||||||
import Header from './Header'
|
|
||||||
import Footer from './Footer'
|
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
|
|
||||||
|
import Footer from './Footer'
|
||||||
|
import Header from './Header'
|
||||||
|
import Menu from './Menu'
|
||||||
|
import Navbar from './Navbar'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
hasHeader?: boolean
|
hasHeader?: boolean
|
||||||
headerChild?: JSX.Element
|
headerChild?: JSX.Element
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Layout extends React.Component<Props, {}> {
|
export default class Layout extends React.Component<Props, {}> {
|
||||||
constructor(props: Props) {
|
public render() {
|
||||||
super(props)
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Navbar>
|
<Navbar>
|
||||||
|
@ -1,15 +1,10 @@
|
|||||||
import React from 'react'
|
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
|
|
||||||
interface Props {
|
export default class Menu extends React.Component<{}, {}> {
|
||||||
}
|
public render() {
|
||||||
|
|
||||||
export default class Menu extends React.Component<Props, {}> {
|
|
||||||
constructor(props: Props) {
|
|
||||||
super(props)
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
return (
|
return (
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
import Link from 'next/link'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { Menu } from 'react-feather'
|
import { Menu } from 'react-feather'
|
||||||
import Link from 'next/link'
|
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -17,7 +18,7 @@ export default class Navbar extends React.Component<Props, States> {
|
|||||||
|
|
||||||
private menuRef = undefined
|
private menuRef = undefined
|
||||||
|
|
||||||
constructor(props: Props) {
|
public constructor(props: Props) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
if (this.props.height) {
|
if (this.props.height) {
|
||||||
@ -25,39 +26,25 @@ export default class Navbar extends React.Component<Props, States> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setRef = element => {
|
public componentDidMount() {
|
||||||
this.menuRef = element
|
|
||||||
}
|
|
||||||
|
|
||||||
onScroll = () => {
|
|
||||||
this.setState({
|
|
||||||
scrolled: window.pageYOffset > 207
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
if (window.location.origin !== config.domain) {
|
if (window.location.origin !== config.domain) {
|
||||||
window.location.replace(`${config.domain}${window.location.pathname}`)
|
window.location.replace(`${config.domain}${window.location.pathname}`)
|
||||||
}
|
}
|
||||||
window.addEventListener('scroll', this.onScroll)
|
window.addEventListener('scroll', this.onScroll)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
public componentWillUnmount() {
|
||||||
window.removeEventListener('scroll', this.onScroll)
|
window.removeEventListener('scroll', this.onScroll)
|
||||||
}
|
}
|
||||||
|
|
||||||
onClick = () => {
|
public render() {
|
||||||
this.menuRef.classList.toggle("shown")
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const height = this.props.height || 80
|
const height = this.props.height || 80
|
||||||
|
|
||||||
// if (!this.state.scrolled)
|
// if (!this.state.scrolled)
|
||||||
|
|
||||||
// console.log(this.state.scrolled)
|
// console.log(this.state.scrolled)
|
||||||
return (
|
return (
|
||||||
<nav className={this.state && this.state.scrolled ? "scrolled" : ""}>
|
<nav className={this.state && this.state.scrolled ? 'scrolled' : ''}>
|
||||||
<style jsx global>{`
|
<style jsx global>{`
|
||||||
body {
|
body {
|
||||||
margin-top: ${height}px;
|
margin-top: ${height}px;
|
||||||
@ -120,9 +107,9 @@ export default class Navbar extends React.Component<Props, States> {
|
|||||||
}
|
}
|
||||||
.head {
|
.head {
|
||||||
display: flex;
|
display: flex;
|
||||||
height: ${height-10}px;
|
height: ${height - 10}px;
|
||||||
background: white;
|
background: white;
|
||||||
padding-left: ${height-10}px;
|
padding-left: ${height - 10}px;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
@ -132,8 +119,8 @@ export default class Navbar extends React.Component<Props, States> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
span {
|
span {
|
||||||
width: ${height-10}px;
|
width: ${height - 10}px;
|
||||||
height: ${height-10}px;
|
height: ${height - 10}px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@ -144,4 +131,18 @@ export default class Navbar extends React.Component<Props, States> {
|
|||||||
</nav>
|
</nav>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setRef = (element) => {
|
||||||
|
this.menuRef = element
|
||||||
|
}
|
||||||
|
|
||||||
|
private onScroll = () => {
|
||||||
|
this.setState({
|
||||||
|
scrolled: window.pageYOffset > 207,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private onClick = () => {
|
||||||
|
this.menuRef.classList.toggle('shown')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import matter from 'gray-matter'
|
import matter from 'gray-matter'
|
||||||
|
|
||||||
|
|
||||||
interface PostInterface {
|
interface PostInterface {
|
||||||
slug: string
|
slug: string
|
||||||
title: string
|
title: string
|
||||||
@ -15,13 +14,22 @@ export interface PostHeader {
|
|||||||
imageAlt?: string
|
imageAlt?: string
|
||||||
date: Date
|
date: Date
|
||||||
url?: string
|
url?: string
|
||||||
tags?: string[]
|
tags?: Array<string>
|
||||||
modifiedDate?: Date
|
modifiedDate?: Date
|
||||||
short?: string
|
short?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Post implements PostInterface {
|
export default class Post implements PostInterface {
|
||||||
|
|
||||||
|
public static async fetchAll(): Promise<Array<Post>> {
|
||||||
|
const files: Array<string> = ((require as any).context('../posts', true, /\.md$/)).keys()
|
||||||
|
const posts: Array<Post> = []
|
||||||
|
for (const file of files) {
|
||||||
|
posts.push(new Post(file.replace('./', '')))
|
||||||
|
}
|
||||||
|
return posts
|
||||||
|
}
|
||||||
|
|
||||||
public slug: string
|
public slug: string
|
||||||
public title: string
|
public title: string
|
||||||
public content: string
|
public content: string
|
||||||
@ -34,7 +42,10 @@ export default class Post implements PostInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async fetch() {
|
public async fetch() {
|
||||||
if (!this.slug.endsWith(".md")) this.slug = "portfolio/" + this.slug + ".md"
|
if (!this.slug.endsWith('.md')) {
|
||||||
|
this.slug = `portfolio/${this.slug}.md`
|
||||||
|
}
|
||||||
|
|
||||||
const content = await import(`../posts/${this.slug}`)
|
const content = await import(`../posts/${this.slug}`)
|
||||||
const md = matter(content.default)
|
const md = matter(content.default)
|
||||||
this.title = md.data.title
|
this.title = md.data.title
|
||||||
@ -43,24 +54,14 @@ export default class Post implements PostInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public fetchSync() {
|
public fetchSync() {
|
||||||
if (!this.slug.endsWith(".md")) this.slug = "portfolio/" + this.slug + ".md"
|
if (!this.slug.endsWith('.md')) {
|
||||||
|
this.slug = `portfolio/${this.slug}.md`
|
||||||
|
}
|
||||||
|
|
||||||
const content = require(`../posts/${this.slug}`)
|
const content = require(`../posts/${this.slug}`)
|
||||||
const md = matter(content.default)
|
const md = matter(content.default)
|
||||||
this.title = md.data.title
|
this.title = md.data.title
|
||||||
this.header = (md.data as PostHeader)
|
this.header = (md.data as PostHeader)
|
||||||
this.content = md.content
|
this.content = md.content
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async fetchAll(): Promise<Post[]> {
|
|
||||||
const files: string[] = ((require as any).context('../posts', true, /\.md$/)).keys()
|
|
||||||
const posts: Post[] = []
|
|
||||||
for (const file of files) {
|
|
||||||
posts.push(
|
|
||||||
new Post(
|
|
||||||
file.replace("./", '')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return posts
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
|
/* tslint:disable:no-empty-interface */
|
||||||
interface Props {}
|
interface Props {}
|
||||||
|
|
||||||
interface States {}
|
interface States {}
|
||||||
|
/* tslint:enable:no-empty-interface */
|
||||||
|
|
||||||
export default class Name extends React.Component<Props, States> {
|
export default class Name extends React.Component<Props, States> {
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props)
|
super(props)
|
||||||
}
|
}
|
||||||
render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<span></span>
|
<span></span>
|
||||||
)
|
)
|
||||||
|
21
config.ts
21
config.ts
@ -1,15 +1,16 @@
|
|||||||
const config = {
|
const config = {
|
||||||
domain: "https://www.avior.me",
|
|
||||||
og: {
|
|
||||||
title: "Avior.me",
|
|
||||||
description: "Avior.me, Site du portfolio de Avior :D"
|
|
||||||
},
|
|
||||||
colors: {
|
colors: {
|
||||||
400: "#BB86FC",
|
rgb500: '98, 0, 238',
|
||||||
500: "#6200EE",
|
400: '#BB86FC',
|
||||||
rgb500: "98, 0, 238",
|
500: '#6200EE',
|
||||||
600: "#3700B3"
|
600: '#3700B3',
|
||||||
}
|
},
|
||||||
|
domain: 'https://www.avior.me',
|
||||||
|
// domain: 'http://localhost:3000',
|
||||||
|
og: {
|
||||||
|
description: 'Avior.me, Site du portfolio de Avior :D',
|
||||||
|
title: 'Avior.me',
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
export default config
|
export default config
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import { NextPageContext } from "next"
|
import { NextPageContext } from 'next'
|
||||||
|
import Head from 'next/head'
|
||||||
import{ Component } from 'react'
|
import Link from 'next/link'
|
||||||
import Post from "../../components/Post"
|
import { Component } from 'react'
|
||||||
import ReactMarkdown from 'react-markdown'
|
import ReactMarkdown from 'react-markdown'
|
||||||
import Error from "../_error"
|
|
||||||
import Link from "next/link"
|
import Post from '../../components/Post'
|
||||||
import Head from "next/head"
|
import config from '../../config'
|
||||||
import config from "../../config"
|
|
||||||
|
import Error from '../_error'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
post: Post
|
post: Post
|
||||||
@ -17,15 +18,34 @@ interface States {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default class PostPage extends Component<Props, 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() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<Head>
|
<Head>
|
||||||
<title key="title">{`${this.props.post.title} - ${config.og.title}`}</title>
|
<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: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 ? (
|
{this.props.post.header.image ? (
|
||||||
<meta key="og:image" property="og:image" content={`${config.domain}${this.props.post.header.image}`}/>
|
<meta key="og:image" property="og:image" content={`${config.domain}${this.props.post.header.image}`}/>
|
||||||
) : undefined}
|
) : undefined}
|
||||||
@ -41,7 +61,7 @@ export default class PostPage extends Component<Props, States> {
|
|||||||
<ul>
|
<ul>
|
||||||
{this.props.post.header.tags.map((el) => (
|
{this.props.post.header.tags.map((el) => (
|
||||||
<li key={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>
|
<a className="button">{el}</a>
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
@ -129,12 +149,4 @@ export default class PostPage extends Component<Props, States> {
|
|||||||
</main>
|
</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}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
import React from 'react'
|
|
||||||
import App from 'next/app'
|
import App from 'next/app'
|
||||||
import '../styl/styl.styl'
|
|
||||||
import Layout from '../components/Layout'
|
|
||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
|
import React from 'react'
|
||||||
|
|
||||||
|
import Layout from '../components/Layout'
|
||||||
import config from '../config'
|
import config from '../config'
|
||||||
|
import '../styl/styl.styl'
|
||||||
|
|
||||||
class MyApp extends App {
|
class MyApp extends App {
|
||||||
render() {
|
public render() {
|
||||||
const { Component, pageProps } = this.props
|
const { Component, pageProps } = this.props
|
||||||
|
|
||||||
return(
|
return(
|
||||||
|
@ -1,17 +1,12 @@
|
|||||||
// _document is only rendered on the server side and not on the client side
|
import Document, { Head, Html, Main, NextScript } from 'next/document'
|
||||||
// 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'
|
|
||||||
|
|
||||||
class MyDocument extends Document {
|
class MyDocument extends Document {
|
||||||
static async getInitialProps(ctx) {
|
public static async getInitialProps(ctx) {
|
||||||
const initialProps = await Document.getInitialProps(ctx)
|
const initialProps = await Document.getInitialProps(ctx)
|
||||||
return { ...initialProps }
|
return { ...initialProps }
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<Html>
|
<Html>
|
||||||
<Head>
|
<Head>
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
import React, { Component } from 'react'
|
|
||||||
import { NextPageContext } from 'next'
|
import { NextPageContext } from 'next'
|
||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
import Layout from '../components/Layout'
|
import React, { Component } from 'react'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
statusCode: number
|
statusCode: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const codesTexts = {
|
const codesTexts = {
|
||||||
404: "Page non trouvé !",
|
404: 'Page non trouvé !',
|
||||||
500: "Le serveur n'a pas pu répondre a ta demande :O"
|
500: "Le serveur n'a pas pu répondre a ta demande :O",
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Error extends Component<Props, {}> {
|
export default class Error extends Component<Props, {}> {
|
||||||
@ -21,7 +20,7 @@ export default class Error extends Component<Props, {}> {
|
|||||||
<title>Pouet :D</title>
|
<title>Pouet :D</title>
|
||||||
</Head>
|
</Head>
|
||||||
<div className="errorContainer">
|
<div className="errorContainer">
|
||||||
<h1>{statusCode ? statusCode : "404"}</h1>
|
<h1>{statusCode ? statusCode : '404'}</h1>
|
||||||
<h2>{statusCode ? codesTexts[statusCode] : codesTexts[404]}</h2>
|
<h2>{statusCode ? codesTexts[statusCode] : codesTexts[404]}</h2>
|
||||||
</div>
|
</div>
|
||||||
<style jsx>{`
|
<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
|
const statusCode = res ? res.statusCode : err ? err.statusCode : 404
|
||||||
return { statusCode }
|
return { statusCode }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,57 +1,30 @@
|
|||||||
|
import { Component } from 'react'
|
||||||
import Element from '../components/Element'
|
import Element from '../components/Element'
|
||||||
import Filters from '../components/Filters'
|
import Filters from '../components/Filters'
|
||||||
import { Component } from 'react'
|
|
||||||
import Post, { PostHeader } from '../components/Post'
|
import Post, { PostHeader } from '../components/Post'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
userAgent?: string
|
userAgent?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface el extends PostHeader {}
|
|
||||||
|
|
||||||
interface States {
|
interface States {
|
||||||
elements: el[]
|
elements: Array<PostHeader>
|
||||||
loaded: boolean
|
loaded: boolean
|
||||||
asideHeight: number
|
asideHeight: number
|
||||||
categories: string[]
|
categories: Array<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
// export const config = {amp: 'hybrid'}
|
// export const config = {amp: 'hybrid'}
|
||||||
|
|
||||||
let elements: PostHeader[] = []
|
let elements: Array<PostHeader> = []
|
||||||
|
|
||||||
export default class Page extends Component<Props, States> {
|
export default class Page extends Component<Props, States> {
|
||||||
|
|
||||||
onQuery = async (query: string, recent: boolean = true) => {
|
public async componentDidMount() {
|
||||||
// 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() {
|
|
||||||
const posts = await Post.fetchAll()
|
const posts = await Post.fetchAll()
|
||||||
const header: Array<PostHeader> = []
|
const header: Array<PostHeader> = []
|
||||||
let cats: Array<string> = []
|
const cats: Array<string> = []
|
||||||
posts.forEach(el => {
|
posts.forEach((el) => {
|
||||||
el.fetchSync()
|
el.fetchSync()
|
||||||
header.push(el.header)
|
header.push(el.header)
|
||||||
cats.push(...el.header.tags)
|
cats.push(...el.header.tags)
|
||||||
@ -64,18 +37,25 @@ export default class Page extends Component<Props, States> {
|
|||||||
|
|
||||||
elements = header
|
elements = header
|
||||||
this.setState({
|
this.setState({
|
||||||
|
categories: cats.filter((item, pos) => cats.indexOf(item) === pos),
|
||||||
elements: header,
|
elements: header,
|
||||||
loaded: true,
|
loaded: true,
|
||||||
categories: cats.filter((item, pos) => {return cats.indexOf(item) === pos})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
public render() {
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<span>
|
<span>
|
||||||
{this.state && this.state.elements && this.state.elements.length !== 0 ? this.state.elements.map((el, index) => (
|
{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 ? (
|
)) : this.state && this.state.loaded ? (
|
||||||
<div>La recherche n'a rien donnée <span className="emoji">😢</span></div>
|
<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;
|
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 {
|
span {
|
||||||
max-width: calc(100% - 400px);
|
max-width: calc(100% - 400px);
|
||||||
}
|
}
|
||||||
@ -116,7 +96,31 @@ export default class Page extends Component<Props, States> {
|
|||||||
}
|
}
|
||||||
`}</style>
|
`}</style>
|
||||||
</main>
|
</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,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,18 @@
|
|||||||
import { NextPage, NextPageContext } from "next"
|
import { NextPage, NextPageContext } from 'next'
|
||||||
import Link from 'next/link'
|
|
||||||
import Post from "../../components/Post"
|
|
||||||
import Element from '../../components/Element'
|
import Element from '../../components/Element'
|
||||||
import Error from "../_error"
|
import Post from '../../components/Post'
|
||||||
// import posts from '../../posts/pages.json'
|
|
||||||
// import firstline from 'firstline'
|
import Error from '../_error'
|
||||||
// import 'fs'
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
files: Post[],
|
files: Array<Post>,
|
||||||
tag: string
|
tag: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const PortfolioIndex: NextPage<Props> = (props: Props) => {
|
const PortfolioIndex: NextPage<Props> = (props: Props) => {
|
||||||
|
|
||||||
const el: JSX.Element[] = []
|
const el: Array<JSX.Element> = []
|
||||||
for (const post of props.files) {
|
for (const post of props.files) {
|
||||||
el.push(
|
el.push(
|
||||||
)
|
)
|
||||||
@ -31,7 +29,13 @@ const PortfolioIndex: NextPage<Props> = (props: Props) => {
|
|||||||
<h2>Tag: {props && props.tag}</h2>
|
<h2>Tag: {props && props.tag}</h2>
|
||||||
<div>
|
<div>
|
||||||
{props.files.map((post, index) => (
|
{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>
|
</div>
|
||||||
<style jsx>{`
|
<style jsx>{`
|
||||||
@ -68,18 +72,24 @@ const PortfolioIndex: NextPage<Props> = (props: Props) => {
|
|||||||
|
|
||||||
PortfolioIndex.getInitialProps = async (context: NextPageContext) => {
|
PortfolioIndex.getInitialProps = async (context: NextPageContext) => {
|
||||||
const { tag } = context.query
|
const { tag } = context.query
|
||||||
if (typeof tag === "object" || tag === "[tag]") return {files: [], tag: ""}
|
if (typeof tag === 'object' || tag === '[tag]') {
|
||||||
const arr: Post[] = []
|
return {files: [], tag: ''}
|
||||||
|
}
|
||||||
|
const arr: Array<Post> = []
|
||||||
for (const post of await Post.fetchAll()) {
|
for (const post of await Post.fetchAll()) {
|
||||||
if (!post.isStarted) await post.fetch()
|
if (!post.isStarted) {
|
||||||
let tags = []
|
await post.fetch()
|
||||||
|
}
|
||||||
|
const tags = []
|
||||||
for (const tg of post.header.tags) {
|
for (const tg of post.header.tags) {
|
||||||
tags.push(tg.toLowerCase())
|
tags.push(tg.toLowerCase())
|
||||||
}
|
}
|
||||||
if (!tags.includes(tag)) continue
|
if (!tags.includes(tag)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
arr.push(post)
|
arr.push(post)
|
||||||
}
|
}
|
||||||
return {files: arr, tag: tag} as Props
|
return {files: arr, tag} as Props
|
||||||
}
|
}
|
||||||
|
|
||||||
export default PortfolioIndex
|
export default PortfolioIndex
|
||||||
|
Loading…
x
Reference in New Issue
Block a user