This commit is contained in:
parent
2df4cc3e3a
commit
199c85a262
|
@ -34,7 +34,7 @@ class Main extends Component {
|
|||
|
||||
list(metadatas: Metadata[]) {
|
||||
const pageOpen = useState<Metadata | undefined>(undefined, "pageOpen");
|
||||
console.log("abcd")
|
||||
|
||||
return <ul>
|
||||
{metadatas.map((n) => {
|
||||
return <li>
|
||||
|
@ -48,15 +48,19 @@ class Main extends Component {
|
|||
})}
|
||||
</ul>
|
||||
}
|
||||
render(blogPosts: Metadata[]) {
|
||||
|
||||
async handleSelfUpdate() {
|
||||
const blogPosts = await fetchBlogPosts()
|
||||
this.update(blogPosts)
|
||||
}
|
||||
|
||||
render(blogPosts: Metadata[]) {
|
||||
const pageOpen = useState<Metadata | undefined>(undefined, "pageOpen");
|
||||
const md = new URLSearchParams(location.search).get("md");
|
||||
|
||||
if (blogPosts) {
|
||||
const found = blogPosts.find(z => z.filename == md);
|
||||
if (found) {
|
||||
console.log(found);
|
||||
pageOpen[1](found);
|
||||
//@ts-expect-error
|
||||
pageOpen[0] = found;
|
||||
|
@ -64,20 +68,21 @@ class Main extends Component {
|
|||
}
|
||||
|
||||
if (pageOpen[0]) {
|
||||
return <BlogPage metadata={pageOpen[0]}></BlogPage>
|
||||
return <div><BlogPage metadata={pageOpen[0]} updateParent={this.handleSelfUpdate.bind(this)}
|
||||
></BlogPage></div>
|
||||
}
|
||||
|
||||
|
||||
return <>
|
||||
return <div>
|
||||
<h1> sophie's blog </h1>
|
||||
<div>Scroll to bottom for comments ↓</div>
|
||||
|
||||
<a style="font-size:xx-large;" href="/">back to main page?</a>
|
||||
{() => {
|
||||
if (blogPosts) return this.list(blogPosts)
|
||||
else return <h3>Loading...</h3>
|
||||
}}
|
||||
<Giscus searchTerm="main"></Giscus>
|
||||
</>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,12 @@ const fetchBlogPost = async (metadata: Metadata) => {
|
|||
|
||||
export class BlogPage extends Component {
|
||||
metadata: Metadata;
|
||||
updateParent: () => void;
|
||||
|
||||
constructor(props: { metadata: Metadata }) {
|
||||
constructor(props: { metadata: Metadata, updateParent: () => void }) {
|
||||
super(props);
|
||||
this.metadata = props.metadata;
|
||||
this.updateParent = props.updateParent;
|
||||
}
|
||||
|
||||
async didMount() {
|
||||
|
@ -26,10 +28,13 @@ export class BlogPage extends Component {
|
|||
|
||||
return <>
|
||||
<h1> sophie's blog </h1>
|
||||
<a href="/blog.html" style="font-size:xx-large;" onClick={() => {
|
||||
<a style="font-size:xx-large;" onClick={() => {
|
||||
pageOpen[1](undefined);
|
||||
this.update();
|
||||
history.replaceState({}, "", location.pathname+"?md=");
|
||||
|
||||
this.updateParent();
|
||||
}}>return back?</a>
|
||||
<div>Scroll to bottom for comments ↓</div>
|
||||
|
||||
{
|
||||
() => {
|
||||
|
|
Loading…
Reference in a new issue