-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/issue 617 add static pages (#618)
* get available links and their title from "Available Pages" wiki page * create generic Page component that restrict pageId possibilities to links from the available pages and add special url /p/ using page id * add WIKI_ROOT to .env file. We will adapt the other links later on, it is used only * add delay and memoid from props in StaticPageLaoder and WikiStaticPage
- Loading branch information
1 parent
4714a13
commit b0480cc
Showing
8 changed files
with
115 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export const randomFakeSentence = (num) => { | ||
let t = '▤' | ||
const characters = ' .!,◎,;▤▤ ▫▫◮◪ ◍◘◎▚▤' | ||
|
||
const charactersLength = characters.length | ||
for (let i = 0; i < num; i++) { | ||
t += characters.charAt(Math.floor(Math.random() * charactersLength)) | ||
} | ||
|
||
return t | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.Page h2:first-of-type { | ||
margin-bottom: var(--spacer-5); | ||
} | ||
.Page h1 { | ||
transition: opacity 0.5s ease-in-out; | ||
} | ||
.Page.loading h1 { | ||
opacity: 0.5; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { useGetRawContents } from '../logic/api/fetchData' | ||
import Loading from './Loading' | ||
import NotFound from './NotFound' | ||
import WikiStaticPage from './WikiStaticPage' | ||
import './Page.css' | ||
|
||
const Page = ({ match }) => { | ||
const { status, data } = useGetRawContents({ | ||
url: process.env.REACT_APP_WIKI_AVAILABLE_PAGES, | ||
delay: 500, | ||
}) | ||
|
||
const { pageId } = match.params | ||
|
||
if (status !== 'success') { | ||
return <Loading /> | ||
} | ||
const availablePages = data.split('\n').map((d) => { | ||
// extract link from markdown text using a regexp | ||
// [The Journal of Digital History switches to single‐blind peer review](https://github.com/C2DH/journal-of-digital-history/wiki/The-Journal-of-Digital-History-switches-to-single-blind-peer-review) | ||
const title = d.match(/\[(.*?)\]/) | ||
const url = d.match(/\((.*?)\)/) | ||
if (!url || !title) { | ||
return null | ||
} | ||
const wikiRawUrl = `${process.env.REACT_APP_WIKI_ROOT}/${pageId}.md` | ||
return { | ||
title: title[1], | ||
url: url[1], | ||
rawUrl: wikiRawUrl, | ||
pageId: url[1].split('/').pop(), | ||
} | ||
}) | ||
console.debug('[Page]', pageId, availablePages) | ||
const page = availablePages.find((d) => d.pageId === pageId) | ||
if (!page) { | ||
return <NotFound /> | ||
} | ||
console.debug('[Page]', pageId, status, data) | ||
return ( | ||
<WikiStaticPage delay={500} url={page.rawUrl} memoid={1} className="Page"> | ||
<h1 className="my-5">{page.title}</h1> | ||
</WikiStaticPage> | ||
) | ||
} | ||
|
||
Page.propTypes = { | ||
match: PropTypes.shape({ | ||
params: PropTypes.shape({ | ||
pageId: PropTypes.string.isRequired, | ||
}).isRequired, | ||
}).isRequired, | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters