Skip to content

Commit 7843ca5

Browse files
committed
site optimization
1 parent aa960c4 commit 7843ca5

File tree

8 files changed

+98
-98
lines changed

8 files changed

+98
-98
lines changed

docs-svelte-kit/src/lib/components/ESLintPlayground.svelte

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script>
2-
import { onDestroy, onMount } from "svelte"
32
import ESLintEditor from "../eslint/ESLintEditor.svelte"
43
import RulesSettings from "../eslint/RulesSettings.svelte"
54
import { deserializeState, serializeState } from "../eslint/scripts/state"
@@ -87,16 +86,6 @@
8786
window.location.replace(`#${serializedString}`)
8887
}
8988
}
90-
onMount(() => {
91-
if (typeof window !== "undefined") {
92-
window.addEventListener("hashchange", onUrlHashChange)
93-
}
94-
})
95-
onDestroy(() => {
96-
if (typeof window !== "undefined") {
97-
window.removeEventListener("hashchange", onUrlHashChange)
98-
}
99-
})
10089
function onLintedResult(evt) {
10190
messages = evt.detail.messages
10291
time = `${evt.detail.time}ms`
@@ -128,6 +117,8 @@
128117
}
129118
</script>
130119

120+
<svelte:window on:hashchange={onUrlHashChange} />
121+
131122
<div class="playground-root">
132123
<div class="playground-tools">
133124
<span style="margin-left: 16px">{time}</span>

docs-svelte-kit/src/lib/footer/Footer.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
<script>
22
import { page } from "$app/stores"
3-
import { normalizePath, menuItems, isActive } from "../utils.js"
3+
import { markdownPath, menuItems, isActive } from "../utils.js"
44
import { base as baseUrl } from "$app/paths"
55
export let fileInfo = {}
66
export let frontmatter = {}
77
88
let prev, next
9-
$: markdownPath = normalizePath($page.path).replace(/^\/|\/$/g, "")
109
$: {
1110
let prevItem, currItem
1211
for (const item of iterateMenuItem($menuItems)) {
@@ -42,7 +41,9 @@
4241
<div class="footer-tools">
4342
<div class="edit-link">
4443
<a
45-
href="https://github.com/ota-meshi/eslint-plugin-svelte/edit/main/docs/{markdownPath}.md"
44+
href="https://github.com/ota-meshi/eslint-plugin-svelte/edit/main/docs/{markdownPath(
45+
$page.path,
46+
)}"
4647
target="_blank"
4748
rel="noopener noreferrer">Edit this page</a
4849
>

docs-svelte-kit/src/lib/markdown/Markdown.svelte

Lines changed: 0 additions & 61 deletions
This file was deleted.

docs-svelte-kit/src/lib/utils.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,15 @@ const SIDE_MENU = {
5353
}
5454

5555
export function isActive(path, $page) {
56-
return normalizePath($page.path) === normalizePath(path)
56+
return markdownPath($page.path) === markdownPath(path)
5757
}
5858

59-
export function normalizePath(path) {
60-
let normalized = path === "/" ? "/README/" : path
61-
if (!normalized.endsWith("/")) {
62-
normalized += "/"
63-
}
64-
return normalized
59+
export function markdownPath(path) {
60+
let normalized = path === "/" ? "README" : path.replace(/^\/|\/$/g, "")
61+
return `${normalized}.md`
6562
}
6663

67-
export const tocStore = writable([])
64+
export const tocStore = writable({ children: [] })
6865

6966
export const menuItems = readable([], function start(set) {
7067
let pageData = {}

docs-svelte-kit/tools/markdown-it-markdown.mjs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,10 @@ class TOCRenderer {
3434
export default (md) => {
3535
md.core.ruler.push("custom_markdown", (state) => {
3636
const tokens = state.tokens
37-
tokens.unshift(new state.Token("custom_markdown_open"))
38-
tokens.push(new state.Token("custom_markdown_close"))
37+
tokens.unshift(new state.Token("custom_markdown_data"))
3938
})
4039
// eslint-disable-next-line camelcase -- ignore
41-
md.renderer.rules.custom_markdown_close = () => `</Markdown>`
42-
// eslint-disable-next-line camelcase -- ignore
43-
md.renderer.rules.custom_markdown_open = (
40+
md.renderer.rules.custom_markdown_data = (
4441
tokens,
4542
_idx,
4643
_options,
@@ -79,13 +76,10 @@ export default (md) => {
7976
fileInfo.timestamp = timestamp
8077
fileInfo.lastUpdated = new Date(timestamp).toLocaleString()
8178
}
82-
return `<script>
83-
import Markdown from "$lib/markdown/Markdown.svelte"
84-
const toc = ${JSON.stringify(renderer.toc())}
85-
const fileInfo = ${JSON.stringify(fileInfo)}
79+
return `<script context="module">
80+
export const toc = ${JSON.stringify(renderer.toc())}
81+
export const fileInfo = ${JSON.stringify(fileInfo)}
8682
</script>
87-
88-
<Markdown {toc} {frontmatter} {fileInfo} >
8983
`
9084
}
9185
}

docs-svelte-kit/tools/markdown-it-replace-link.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// eslint-disable-next-line eslint-comments/disable-enable-pair -- ignore
22
/* eslint-disable camelcase -- ignore */
3-
// markdown-it plugin for:
4-
// 1. adding target="_blank" to external links
5-
// 2. converting internal links to remove .md
63
import path from "path"
74

85
export default (md, options = {}) => {

docs/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ module.exports = {
55
rules: {
66
"eslint-comments/require-description": "off",
77
"prettier/prettier": "off",
8+
"require-jsdoc": "off",
89
},
910
}

docs/__layout.svelte

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,86 @@
1+
<script context="module">
2+
import { markdownPath } from "$lib/utils.js"
3+
const docs = import.meta.glob("./**/*.md")
4+
5+
/** @type {import('@sveltejs/kit').Load} */
6+
export async function load({ page }) {
7+
return {
8+
props: {
9+
moduleData: await docs[`./${markdownPath(page.path)}`](),
10+
},
11+
}
12+
}
13+
</script>
14+
115
<script>
16+
import Header from "$lib/header/Header.svelte"
17+
import SideMenu from "$lib/sidemenu/SideMenu.svelte"
18+
import Footer from "$lib/footer/Footer.svelte"
19+
220
import "../docs-svelte-kit/src/app.css"
321
import "../docs-svelte-kit/src/site.css"
22+
import { tocStore } from "$lib/utils"
23+
24+
export let moduleData
25+
26+
$: frontmatter = moduleData.frontmatter
27+
$: fileInfo = moduleData.fileInfo
28+
$: {
29+
const toc = moduleData.toc
30+
tocStore.update(() => toc)
31+
}
32+
33+
let sidebarOpen = false
34+
35+
function handleToggleSidebar() {
36+
sidebarOpen = !sidebarOpen
37+
}
38+
function resetSidebarOpen() {
39+
sidebarOpen = false
40+
}
441
</script>
542

6-
<slot />
43+
<svelte:window on:resize={sidebarOpen ? resetSidebarOpen : null} />
44+
45+
<Header on:toggle-sidebar-open={handleToggleSidebar} />
46+
47+
<SideMenu {sidebarOpen} hiddenMenu={frontmatter.hiddenMenu} />
48+
49+
<main
50+
class:hidden-menu={frontmatter.hiddenMenu}
51+
on:click={sidebarOpen ? resetSidebarOpen : null}
52+
>
53+
<div class="main-content">
54+
<slot />
55+
</div>
56+
</main>
57+
58+
<Footer {frontmatter} {fileInfo} />
59+
60+
<style>
61+
main:not(.hidden-menu) {
62+
padding-left: 20rem;
63+
}
64+
65+
@media (max-width: 959px) {
66+
main:not(.hidden-menu) {
67+
padding-left: 16.4rem;
68+
}
69+
}
70+
@media (max-width: 719px) {
71+
main:not(.hidden-menu) {
72+
padding-left: 0;
73+
}
74+
}
75+
76+
main .main-content {
77+
flex: 1;
78+
display: flex;
79+
flex-direction: column;
80+
padding: 1rem;
81+
width: 100%;
82+
max-width: 1024px;
83+
margin: 0 auto;
84+
box-sizing: border-box;
85+
}
86+
</style>

0 commit comments

Comments
 (0)