Skip to content

Commit 7cefbcd

Browse files
committed
revert: remove unrelated files from PR
1 parent c334a37 commit 7cefbcd

File tree

5 files changed

+48
-14
lines changed

5 files changed

+48
-14
lines changed

src/components/Page/Page.jsx

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ export default function Page(props) {
2525
} = props;
2626

2727
const isDynamicContent = props.content instanceof Promise;
28-
const [content, setContent] = useState(
29-
isDynamicContent
30-
? placeholderString()
31-
: () => props.content.default || props.content,
28+
const [dynamicContent, setContent] = useState(
29+
isDynamicContent ? placeholderString() : null,
3230
);
31+
const content = isDynamicContent
32+
? dynamicContent
33+
: props.content.default || props.content;
34+
3335
const [contentLoaded, setContentLoaded] = useState(!isDynamicContent);
3436

3537
useEffect(() => {
@@ -44,6 +46,7 @@ export default function Page(props) {
4446
}, [props.content]);
4547

4648
const { hash, pathname } = useLocation();
49+
const isBlogIndex = pathname === "/blog/";
4750

4851
useEffect(() => {
4952
let observer;
@@ -52,13 +55,15 @@ export default function Page(props) {
5255
const target = document.querySelector("#md-content");
5356
// two cases here
5457
// 1. server side rendered page, so hash target is already there
55-
if (document.querySelector(hash)) {
56-
document.querySelector(hash).scrollIntoView();
58+
// Note: Why this change because we use getElementById instead of querySelector(hash) here because
59+
// CSS selectors cannot start with a digit (e.g. #11-in-scope is invalid)
60+
if (document.getElementById(hash.slice(1))) {
61+
document.getElementById(hash.slice(1)).scrollIntoView();
5762
} else {
5863
// 2. dynamic loaded content
5964
// we need to observe the dom change to tell if hash exists
6065
observer = new MutationObserver(() => {
61-
const element = document.querySelector(hash);
66+
const element = document.getElementById(hash.slice(1));
6267
if (element) {
6368
element.scrollIntoView();
6469
}
@@ -99,9 +104,12 @@ export default function Page(props) {
99104
);
100105
}
101106
return (
102-
<section className="page">
107+
<main id="main-content" className="page">
103108
<Markdown>
104109
<h1>{title}</h1>
110+
{rest.date && pathname.startsWith("/blog/") && !isBlogIndex && (
111+
<div className="blog-post-date">{rest.date}</div>
112+
)}
105113

106114
{rest.thirdParty ? (
107115
<div className="italic my-[20px]">
@@ -114,6 +122,27 @@ export default function Page(props) {
114122

115123
<div id="md-content">{contentRender}</div>
116124

125+
{rest.url === "/blog/" && (
126+
<div className="blog-list">
127+
{(props.pages || [])
128+
.filter((post) => post.url !== "/blog/")
129+
.map((post) => (
130+
<div key={post.url} className="blog-post-item">
131+
<h2>
132+
<Link to={post.url}>{post.title}</Link>
133+
</h2>
134+
{post.date && (
135+
<div className="blog-post-date">{post.date}</div>
136+
)}
137+
<p>{post.teaser}</p>
138+
<Link to={post.url} className="read-more">
139+
Read More &rarr;
140+
</Link>
141+
</div>
142+
))}
143+
</div>
144+
)}
145+
117146
{loadRelated && (
118147
<div className="print:hidden">
119148
<h2>Further Reading</h2>
@@ -129,7 +158,7 @@ export default function Page(props) {
129158

130159
<PageLinks page={rest} />
131160

132-
{(previous || next) && (
161+
{!isBlogIndex && (previous || next) && (
133162
<AdjacentPages previous={previous} next={next} />
134163
)}
135164

@@ -143,7 +172,7 @@ export default function Page(props) {
143172
</div>
144173
)}
145174
</Markdown>
146-
</section>
175+
</main>
147176
);
148177
}
149178

@@ -153,6 +182,7 @@ Page.propTypes = {
153182
related: PropTypes.array,
154183
previous: PropTypes.object,
155184
next: PropTypes.object,
185+
pages: PropTypes.array,
156186
content: PropTypes.oneOfType([
157187
PropTypes.string,
158188
PropTypes.func,

src/components/Sidebar/Sidebar.jsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ export default function Sidebar({ className = "", pages, currentPage }) {
3131
<nav className={`sidebar ${className}`}>
3232
<div className="sidebar__inner">
3333
<div className="relative z-0 bg-white dark:bg-gray-100 ">
34+
<label htmlFor="docs-version" className="sr-only">
35+
Select webpack version
36+
</label>
3437
<select
38+
id="docs-version"
3539
className="text-gray-600 text-14 px-5 py-5 appearance-none box-border border border-gray-200 border-solid flex-col flex w-full rounded-none bg-transparent bg-none"
3640
value={version}
3741
onChange={(event) => {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`customize blockquote should transform W> into aside of warning 1`] = `
4-
"<aside class="warning"><h6 class="warning__prefix">warning</h6><p>hello world</p></aside>
4+
"<aside class="warning"><p class="warning__prefix">warning</p><p>hello world</p></aside>
55
"
66
`;

src/remark-plugins/remark-custom-asides/index.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ export default function remarkCustomAsides(
3737
// remove custom characters from paragraph
3838
node.children = [
3939
{
40-
type: "heading",
41-
depth: 6,
40+
type: "paragraph",
4241
data: {
4342
// see https://github.com/syntax-tree/mdast-util-to-hast#hname
4443
// add a className to heading
44+
hName: "p",
4545
hProperties: {
4646
className: `${className}__prefix`,
4747
},

src/remark-plugins/remark-custom-asides/index.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ W> hello world
2020
(err, { value: contents }) => {
2121
expect(err).toBeUndefined();
2222
expect(contents).toContain('<aside class="warning"');
23-
expect(contents).toContain('<h6 class="warning__prefix"');
23+
expect(contents).toContain('<p class="warning__prefix"');
2424
expect(contents).toContain("warning");
2525
expect(contents).toMatchSnapshot();
2626
},

0 commit comments

Comments
 (0)