Compare commits

..

3 commits

6 changed files with 220 additions and 63 deletions

View file

@ -16,6 +16,10 @@ const isActive = (href: string)=>{
return href === pathname || href === pathname.split('/').slice(0,2).join('/'); return href === pathname || href === pathname.split('/').slice(0,2).join('/');
} }
function handleMenu(e) {
console.log(e);
}
--- ---
<header> <header>
@ -34,8 +38,25 @@ const isActive = (href: string)=>{
</ul> </ul>
</div> </div>
<div class="right"> <div class="right">
<div class="search"><p>Search TODO</p></div> <div class="search"><p>Search TODO</p></div>
<btn class="menu"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></btn> <btn id="menu">
<span></span>
<span></span>
<span></span>
</btn>
</div> </div>
</nav> </nav>
</header> </header>
<script>
const btn = document.querySelector('#menu');
btn.addEventListener('click', () => {
btn.classList.toggle('open');
document.querySelectorAll('.sidebar').forEach(sidebar=>{
sidebar.classList.toggle('active');
})
});
</script>
<style>
</style>

View file

@ -3,12 +3,10 @@
import TableOfContentsHeading from "./TableOfContentsHeading.astro"; import TableOfContentsHeading from "./TableOfContentsHeading.astro";
import TocItem from '../utils/generateToc.ts'; import TocItem from '../utils/generateToc.ts';
const { headings, edit } = Astro.props; const { headings, edit } = Astro.props;
import { REPOSITORY, edit_page } from "../config"; import { REPOSITORY } from "../config";
const toc = headings && headings.length ? TocItem(headings) : []; const toc = headings && headings.length ? TocItem(headings) : [];
console.log(edit);
--- ---
<section class="toc"> <section class="toc">
@ -23,19 +21,12 @@ console.log(edit);
</section> </section>
<style is:inline> <style is:inline>
.toc { .toc {
position: fixed;
width: calc(var(--sidebar-width) - 2rem); width: calc(var(--sidebar-width) - 2rem);
height: fit-content; height: 100%;
overflow-y: auto; overflow-y: scroll;
max-height: calc(100vh - var(--nav-height) - 2rem * 2); /* max-height: 80%; */
inset-block: 0; /* inset-block: 0; */
inset-inline-end: 2rem;
margin-top: calc(2rem + var(--nav-height));
margin-bottom: 2rem;
border-radius: 1em;
background-color: var(--secondary-background);
transition: 0.3s; transition: 0.3s;
z-index: 10;
} }
.toc .container { .toc .container {
@ -67,12 +58,12 @@ console.log(edit);
} }
@media only screen and (max-width: 750px) { @media only screen and (max-width: 750px) {
.toc { /* .toc {
margin-top: var(--nav-height); margin-top: var(--nav-height);
margin-bottom: 0; margin-bottom: 0;
inset-inline-start: 0; inset-inline-start: 0;
inset-inline-end: unset; inset-inline-end: unset;
transform: translateX(-100%); transform: translateX(-100%);
} } */
} }
</style> </style>

View file

@ -35,6 +35,11 @@ const isActive = (href: string)=>{
<Layout title={frontmatter.title}> <Layout title={frontmatter.title}>
<div class="wrapper"> <div class="wrapper">
<section class="sidebar"> <section class="sidebar">
{(headings && headings.length) ? (
<aside id="toc">
<TableOfContents headings={headings} />
</aside>
) : ''}
<div class="container"> <div class="container">
{items.length ? ( {items.length ? (
<summary> <summary>
@ -50,15 +55,17 @@ const isActive = (href: string)=>{
</section> </section>
<div class="main"> <div class="main">
<div class="content"> <div class="content">
<aside id="toc"> <!-- {headings && (
<TableOfContents headings={headings} edit={'src/content' + pathname + '.md'} /> <aside id="toc">
</aside> <TableOfContents headings={headings} />
</aside>
)} -->
<div class="markdown-body"> <div class="markdown-body">
<h1>{frontmatter.title}</h1> <h1>{frontmatter.title}</h1>
<h3><Fragment set:html={description}/></h3> <h3><Fragment set:html={description}/></h3>
<slot/> <slot/>
{!noedit && ( {!noedit && (
<hr> <hr/>
<a class="edit" href={`https://github.com/${REPOSITORY}/tree/master/src/content${pathname}.mdx`} target="_blank">{EDIT_PAGE}</a> <a class="edit" href={`https://github.com/${REPOSITORY}/tree/master/src/content${pathname}.mdx`} target="_blank">{EDIT_PAGE}</a>
)} )}
</div> </div>
@ -68,24 +75,29 @@ const isActive = (href: string)=>{
<style> <style>
.wrapper { .wrapper {
display: flex; display: flex;
/* max-width: 1000px; */
} }
.wrapper .sidebar { .wrapper .sidebar {
position: fixed; position: fixed;
width: var(--sidebar-width); width: var(--sidebar-width);
height: 100vh; height: 100%;
max-height: calc(100% - var(--nav-height));
overflow-y: auto; overflow-y: auto;
inset-block: 0; inset-block: 0;
inset-inline-start: 0; inset-inline-start: 0;
margin-top: var(--nav-height);
padding-bottom: var(--nav-height);
/* padding: 20px; */ /* padding: 20px; */
padding-top: var(--nav-height); // padding: var(--nav-height) 0;
background-color: var(--secondary-background); background-color: var(--secondary-background);
transition: 0.3s; transition: 0.3s;
z-index: 10;
} }
.wrapper .sidebar .container { .wrapper .sidebar .container {
position: relative;
padding: 1rem 1rem 0; padding: 1rem 1rem 0;
// height: calc(100vh - var(--nav-height)*2);
} }
.wrapper .sidebar summary .title { .wrapper .sidebar summary .title {
@ -148,23 +160,42 @@ const isActive = (href: string)=>{
margin: 1rem; margin: 1rem;
} }
.wrapper .main aside {
display: flex;
align-items: center;
order: 2;
width: fit-content;
max-width: 25%;
margin: 0 auto;
}
.wrapper .markdown-body { .wrapper .markdown-body {
// padding: 10px 20px; // padding: 10px 20px;
width: 100%; width: 100%;
} }
.wrapper #toc { .wrapper #toc {
display: flex; position: fixed;
flex-direction: column; width: calc(var(--sidebar-width) - 2rem);
height: fit-content;
max-height: calc(100vh - var(--nav-height)*2 - 2rem * 2);
inset-block: 0;
inset-inline-end: 2rem;
margin: calc(2rem + var(--nav-height)) 0;
// background-color: var(--secondary-background);
transition: 0.3s;
z-index: 10;
overflow-y: auto;
border-radius: 1em;
background-color: var(--secondary-background);
}
@media only screen and (max-width: 1000px) {
.wrapper #toc {
position: relative;
width: var(--sidebar-width);
max-height: unset;
inset-block: unset;
inset-inline-end: unset;
margin-top: 0;
z-index: 1;
background-color: transparent;
}
.wrapper .main {
padding-inline-end: unset;
}
} }
@media only screen and (max-width: 750px) { @media only screen and (max-width: 750px) {
@ -172,9 +203,13 @@ const isActive = (href: string)=>{
transform: translateX(-100%); transform: translateX(-100%);
} }
.wrapper .sidebar.active {
transform: translateX(0);
}
.wrapper .main { .wrapper .main {
padding-inline-start: unset; padding-inline-start: unset;
padding-inline-end: unset;
} }
} }
</style> </style>

View file

@ -17,13 +17,15 @@ const description = await markdown.parse(frontmatter.description);
<Layout title={frontmatter.title}> <Layout title={frontmatter.title}>
<div class="wrapper"> <div class="wrapper">
<section class="sidebar">
{headings && (
<aside id="toc">
<TableOfContents headings={headings} />
</aside>
)}
</section>
<div class="main"> <div class="main">
<div class="content"> <div class="content">
{headings && (
<aside class="toc">
<TableOfContents headings={headings} />
</aside>
)}
<div class="markdown-body"> <div class="markdown-body">
<h1>{frontmatter.title}</h1> <h1>{frontmatter.title}</h1>
<h3><Fragment set:html={description}/></h3> <h3><Fragment set:html={description}/></h3>
@ -50,32 +52,75 @@ const description = await markdown.parse(frontmatter.description);
margin: 1rem; margin: 1rem;
} }
.wrapper .main aside {
display: flex;
align-items: center;
order: 2;
/* max-width: 25%; */
margin: 0 auto;
}
.wrapper .markdown-body { .wrapper .markdown-body {
/* margin: 10px 20px; */ /* margin: 10px 20px; */
/* max-width: 75%; */ /* max-width: 75%; */
max-width: 100%; max-width: 100%;
} }
.wrapper .toc { .wrapper #toc {
display: flex; position: fixed;
flex-direction: column; width: calc(var(--sidebar-width) - 2rem);
height: fit-content;
max-height: calc(100vh - var(--nav-height)*2 - 2rem * 2);
inset-block: 0;
inset-inline-end: 2rem;
margin: calc(2rem + var(--nav-height)) 0;
background-color: var(--secondary-background);
transition: 0.3s;
z-index: 10;
overflow-y: auto;
border-radius: 1em;
background-color: var(--secondary-background);
}
@media only screen and (max-width: 1000px) {
.wrapper .sidebar {
position: fixed;
width: var(--sidebar-width);
height: 100%;
max-height: calc(100% - var(--nav-height));
overflow-y: auto;
inset-block: 0;
inset-inline-start: 0;
margin-top: var(--nav-height);
padding-bottom: var(--nav-height);
/* padding: 20px; */
// padding: var(--nav-height) 0;
background-color: var(--secondary-background);
transition: 0.3s;
z-index: 10;
}
.wrapper #toc {
position: relative;
width: var(--sidebar-width);
max-height: unset;
inset-block: unset;
inset-inline-end: unset;
margin-top: 0;
z-index: 1;
background-color: transparent;
}
.wrapper .main {
width: 100%;
padding-inline-start: var(--sidebar-width);
}
} }
@media only screen and (max-width: 750px) { @media only screen and (max-width: 750px) {
.wrapper .sidebar { .wrapper .sidebar {
transform: translateX(-80%); transform: translateX(-100%);
}
.wrapper .sidebar.active {
transform: translateX(0);
} }
.wrapper .main { .wrapper .main {
padding-inline-start: calc(400px * 0.2); width: 100%;
padding-inline-start: 0;
} }
} }
</style> </style>

View file

@ -41,17 +41,74 @@ header ul li:hover a {
list-style: none; list-style: none;
} }
header .right .menu { header .right #menu {
display: none; display: none;
cursor: pointer;
} }
@media only screen and (max-width: 600px) { #menu {
flex-direction: column;
/* justify-content: space-between; */
justify-content: center;
width: 2rem;
height: 1.5rem;
position: relative;
/* margin: 50px auto; */
-webkit-transition: .5s ease-in-out;
-moz-transition: .5s ease-in-out;
-o-transition: .5s ease-in-out;
transition: .5s ease-in-out;
cursor: pointer;
/* border:1px solid red; */
}
#menu span {
display: block;
position: absolute;
height: 3px;
width: 100%;
background: var(--header-text);
border-radius: 9px;
opacity: 1;
left: 0;
transform: rotate(0deg);
transition: .2s ease-in-out;
/* border:4px solid black; */
}
#menu span:nth-child(1) {
top: 0;
}
#menu span:nth-child(3) {
bottom: 0;
}
#menu.open span:nth-child(1) {
top: 50%;
transform: translateY(-50%);
transform: rotate(45deg);
}
#menu.open span:nth-child(2) {
width: 0;
left: 50%;
transform: translateX(-50%);
}
#menu.open span:nth-child(3) {
top: 50%;
transform: translateY(-50%);
transform: rotate(-45deg);
}
@media only screen and (max-width: 750px) {
header .left ul, header .right .search { header .left ul, header .right .search {
display: none; display: none;
} }
header .right .menu { header .right #menu {
display: block; display: flex;
width: 25px; /* width: 25px; */
} }
} }

View file

@ -30,12 +30,20 @@
} }
} }
@media only screen and (max-width: 750px) {
:root {
--sidebar-width: 80vw;
}
}
* { * {
margin: 0; margin: 0;
box-sizing: border-box; box-sizing: border-box;
} }
*:target{ padding-top: 100px;margin-top: -100px} *:target{
scroll-margin-top: calc(var(--nav-height) + 1em);
}
html { html {
font-family: 'Roboto', sans-serif; font-family: 'Roboto', sans-serif;