Skip to content

Commit defccbf

Browse files
test
1 parent ed097b4 commit defccbf

File tree

4 files changed

+37
-16
lines changed

4 files changed

+37
-16
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ <h2 class="sidebar-title">전공무관</h2>
3030
<div>검색</div>
3131
</div>
3232
<div class="sidebar-feature">
33-
<a href="./"></a>
33+
<a href="/"></a>
3434
</div>
3535
</div>
3636
<h3 class="myPage">내 페이지</h3>

src/components/Sidebar.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ function renderTree(documents, parentElement = sidebarTree, depth = 0) {
129129
const toggleBtn = document.createElement("button")
130130
toggleBtn.className = "toggle-btn"
131131
toggleBtn.type = "button"
132-
toggleBtn.style.backgroundImage = "url(/src/img/toggle.svg)"
133-
toggleBtn.style.backgroundRepeat = "no-repeat"
134-
toggleBtn.style.backgroundSize = "cover"
135-
toggleBtn.style.backgroundPosition = "center"
136132
toggleBtn.style.marginRight = "6px"
137133
toggleBtn.style.fontSize = "0.8rem"
138134
toggleBtn.style.lineHeight = "1"

src/router.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { EditPage } from "./components/Editor.js"
22

33
const $content = document.getElementById("content")
44

5+
let BASE_PATH = ""
6+
57
// 라우팅 처리 함수
68
function matchRoute(path) {
79
if (path === "/") return routes["/"]
@@ -25,7 +27,7 @@ const routes = {
2527
$content.innerHTML = "<h1>문서 목록</h1>"
2628
// 예시: 목록을 클릭하면 특정 id 문서로 이동
2729
const link = document.createElement("a")
28-
link.href = "/documents/123"
30+
link.href = `${BASE_PATH}/documents/123`
2931
link.textContent = "문서 123 보기"
3032
link.addEventListener("click", (e) => {
3133
e.preventDefault()
@@ -44,7 +46,7 @@ const routes = {
4446
}
4547

4648
export function navigateTo(path) {
47-
history.pushState({ path }, "", path)
49+
history.pushState({ path }, "", `${BASE_PATH}${path}`)
4850
loadContent(path)
4951
}
5052

@@ -61,5 +63,27 @@ window.addEventListener("popstate", (e) => {
6163

6264
// 첫 로딩
6365
window.addEventListener("DOMContentLoaded", () => {
64-
loadContent(location.pathname)
66+
const pathSegments = location.pathname.split("/").filter(Boolean)
67+
if (location.hostname.endsWith("github.io") && pathSegments.length > 0) {
68+
BASE_PATH = `/${pathSegments[0]}`
69+
} else {
70+
BASE_PATH = ""
71+
}
72+
73+
let initialBrowserPath = location.pathname
74+
let pathForRouter = "/"
75+
76+
if (initialBrowserPath.startsWith(BASE_PATH)) {
77+
pathForRouter = initialBrowserPath.substring(BASE_PATH.length)
78+
if (pathForRouter === "") {
79+
pathForRouter = "/"
80+
}
81+
}
82+
const restoredPath = history.state?.path
83+
const finalPathToLoad =
84+
restoredPath && restoredPath.startsWith(BASE_PATH)
85+
? restoredPath.substring(BASE_PATH.length) || "/"
86+
: pathForRouter
87+
88+
loadContent(finalPathToLoad)
6589
})

src/styles/main.css

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
/* 사이드바 오픈 버튼 */
88
.open-btn {
99
display: none;
10-
background: url(/src/img/sidemenu.svg) no-repeat center/cover;
10+
background: url(../img/sidemenu.svg) no-repeat center/cover;
1111
width: 30px;
1212
height: 30px;
1313
margin: 10px;
1414
}
1515

1616
.open-btn:hover {
17-
background: url(/src/img/arrowopen.svg) no-repeat center/cover;
17+
background: url(../img/arrowopen.svg) no-repeat center/cover;
1818
transition: all 0.2s;
1919
}
2020

@@ -61,7 +61,7 @@
6161
}
6262

6363
.create-root-btn {
64-
background: url(/src/img/headercreate.svg) no-repeat center/cover;
64+
background: url(../img/headercreate.svg) no-repeat center/cover;
6565
}
6666

6767
.create-root-btn:hover,
@@ -70,7 +70,7 @@
7070
}
7171

7272
.hide-btn {
73-
background: url(/src/img/arrowhide.svg) no-repeat center/cover;
73+
background: url(../img/arrowhide.svg) no-repeat center/cover;
7474
}
7575

7676
.sidebar-features {
@@ -101,7 +101,7 @@
101101
width: 21px;
102102
height: 21px;
103103
margin-right: 6px;
104-
background: url("/src/img/search.svg") no-repeat center/cover;
104+
background: url(../img/search.svg) no-repeat center/cover;
105105
}
106106

107107
/* 두 번째 sidebar-feature (홈 아이콘) */
@@ -111,7 +111,7 @@
111111
position: absolute;
112112
width: 21px;
113113
height: 21px;
114-
background: url("/src/img/home.svg") no-repeat center/cover;
114+
background: url(../img/home.svg) no-repeat center/cover;
115115
}
116116

117117
.sidebar-feature a {
@@ -211,11 +211,11 @@ textarea {
211211

212212
/* delete btn */
213213
.delete-btn {
214-
background: url(/src/img/delete.svg) no-repeat center/cover;
214+
background: url(../img/delete.svg) no-repeat center/cover;
215215
}
216216

217217
.add-btn {
218-
background: url(/src/img/plus.svg) no-repeat center/cover;
218+
background: url(../img/plus.svg) no-repeat center/cover;
219219
}
220220

221221
.delete-btn:hover,
@@ -258,6 +258,7 @@ textarea {
258258
/* toggle 버튼 hover */
259259
.toggle-btn {
260260
transition: all 0.15s ease;
261+
background: url(../img/toggle.svg) no-repeat center/cover;
261262
}
262263

263264
.toggle-btn:hover {

0 commit comments

Comments
 (0)