Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/palette.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@
## 2024-08-01 - ๋„ค์ดํ‹ฐ๋ธŒ ๋ธŒ๋ผ์šฐ์ € UI์˜ ๋‹คํฌ ๋ชจ๋“œ ์ง€์› ๊ฐ•์ œ
**ํ•™์Šต:** CSS ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ(`@media (prefers-color-scheme: dark)`)๋ฅผ ํ†ตํ•ด ๋‹คํฌ ๋ชจ๋“œ๋ฅผ ์ง€์›ํ•˜๋”๋ผ๋„, ๋ธŒ๋ผ์šฐ์ €์˜ ๋„ค์ดํ‹ฐ๋ธŒ UI ์š”์†Œ(์Šคํฌ๋กค๋ฐ”, ๊ธฐ๋ณธ ํผ ์ปจํŠธ๋กค, ๊ธฐ๋ณธ ๋ฐฑ๊ทธ๋ผ์šด๋“œ ๋“ฑ)๋Š” ํ…Œ๋งˆ ๋ณ€๊ฒฝ์„ ์ธ์‹ํ•˜์ง€ ๋ชปํ•ด ์–ด๋‘์šด ํ…Œ๋งˆ ํ™˜๊ฒฝ์—์„œ ๋ฐ์€ ์Šคํฌ๋กค๋ฐ”๊ฐ€ ํ‘œ์‹œ๋˜๋Š” ๋“ฑ ์‹œ๊ฐ์  ๋ถˆ์ผ์น˜๋ฅผ ์ดˆ๋ž˜ํ•ฉ๋‹ˆ๋‹ค.
**์กฐ์น˜:** ํ•ญ์ƒ HTML ๋ฌธ์„œ์˜ `<head>` ์˜์—ญ์— `<meta name="color-scheme" content="light dark">` ๋ฉ”ํƒ€ ํƒœ๊ทธ๋ฅผ ๋ช…์‹œ์ ์œผ๋กœ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ธŒ๋ผ์šฐ์ € ์ˆ˜์ค€์—์„œ ์‚ฌ์šฉ์ž์˜ ์‹œ์Šคํ…œ ํ…Œ๋งˆ(๋‹คํฌ ๋ชจ๋“œ ๋“ฑ)๋ฅผ ์™„์ „ํžˆ ์ƒ์†๋ฐ›์•„ ์ผ๊ด€์„ฑ ์žˆ๋Š” ๋„ค์ดํ‹ฐ๋ธŒ UI๋ฅผ ๋ Œ๋”๋งํ•˜๋„๋ก ๋ณด์žฅํ•˜์‹ญ์‹œ์˜ค.
## 2026-07-15 - Provide fallback for empty directory names
**Learning:** In Java/Kotlin, root directories return an empty string for `getName()`. This results in empty `<title>` and `<h1>` tags, which harms accessibility. Fallbacks (e.g. `absolutePath`) must be provided for UI elements.
**Action:** Use `name.ifEmpty { absolutePath }` when generating HTML content from File objects to ensure semantic tags are properly populated.
4 changes: 2 additions & 2 deletions src/main/kotlin/html4tree/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ ${cssContent} </style>
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src '${styleHash}'; base-uri 'none'; form-action 'none';">
<!-- ๋ณด์•ˆ ํ–ฅ์ƒ: ๋ฆฌํผ๋Ÿฌ๋ฅผ ํ†ตํ•œ ๋””๋ ‰ํ† ๋ฆฌ ๊ฒฝ๋กœ ๋…ธ์ถœ ๋ฐฉ์ง€ -->
<meta name="referrer" content="no-referrer">
<title>${curr_dir.getName().escapeHtml()}</title>
<title>${curr_dir.name.ifEmpty { curr_dir.absolutePath }.escapeHtml()}</title>
${css}
</head>
<body>
<main>
<h1>${curr_dir.getName().escapeHtml()}</h1>
<h1>${curr_dir.name.ifEmpty { curr_dir.absolutePath }.escapeHtml()}</h1>
<nav aria-label="๋””๋ ‰ํ† ๋ฆฌ ๋ชฉ๋ก">
<ul role="list">
<li><a class="dir-link" href="./.." aria-label="์ƒ์œ„ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™" title="์ƒ์œ„ ๋””๋ ‰ํ† ๋ฆฌ๋กœ ์ด๋™"><span class="icon" aria-hidden="true">&#x21B0;</span> <span>..</span></a></li>
Expand Down
53 changes: 48 additions & 5 deletions src/test/kotlin/html4tree/MainTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ class MainTest {
assertTrue(htmlContent.contains("<html lang=\"ko\">"))
assertTrue(htmlContent.contains("์ด ๋””๋ ‰ํ† ๋ฆฌ๋Š” ๋น„์–ด ์žˆ์Šต๋‹ˆ๋‹ค."))
assertTrue(htmlContent.contains("role=\"list\""))
assertTrue(htmlContent.contains("<title>${tempDir.name.escapeHtml()}</title>"))
assertTrue(htmlContent.contains("<h1>${tempDir.name.escapeHtml()}</h1>"))
}

@Test
Expand Down Expand Up @@ -308,6 +310,8 @@ class MainTest {
assertTrue(indexFile.exists())
val htmlContent = indexFile.readText()
assertTrue(htmlContent.contains("<html lang=\"ko\">"))
assertTrue(htmlContent.contains("<title>${tempDir.name.escapeHtml()}</title>"))
assertTrue(htmlContent.contains("<h1>${tempDir.name.escapeHtml()}</h1>"))
assertTrue(htmlContent.contains("<meta name=\"color-scheme\" content=\"light dark\">"))
assertTrue(htmlContent.contains("<nav aria-label=\"๋””๋ ‰ํ† ๋ฆฌ ๋ชฉ๋ก\">"))
assertTrue(htmlContent.contains("role=\"list\""))
Expand Down Expand Up @@ -401,7 +405,11 @@ class MainTest {

go(tempDir.absolutePath, -1)

assertTrue(File(tempDir, "index.html").exists())
val indexFile = File(tempDir, "index.html")
assertTrue(indexFile.exists())
val htmlContent = indexFile.readText()
assertTrue(htmlContent.contains("<title>${tempDir.name.escapeHtml()}</title>"))
assertTrue(htmlContent.contains("<h1>${tempDir.name.escapeHtml()}</h1>"))

val subdirIndex = File(subdir, "index.html")
assertTrue(subdirIndex.exists())
Expand All @@ -423,7 +431,12 @@ class MainTest {

go(tempDir.absolutePath, 0)

assertTrue(File(tempDir, "index.html").exists())
val indexFile = File(tempDir, "index.html")
assertTrue(indexFile.exists())
val htmlContent = indexFile.readText()
assertTrue(htmlContent.contains("<title>${tempDir.name.escapeHtml()}</title>"))
assertTrue(htmlContent.contains("<h1>${tempDir.name.escapeHtml()}</h1>"))

assertFalse(File(subdir, "index.html").exists())
assertFalse(File(subsubdir, "index.html").exists())
}
Expand All @@ -438,7 +451,12 @@ class MainTest {

go(tempDir.absolutePath, -1)

assertTrue(File(tempDir, "index.html").exists())
val indexFile = File(tempDir, "index.html")
assertTrue(indexFile.exists())
val htmlContent = indexFile.readText()
assertTrue(htmlContent.contains("<title>${tempDir.name.escapeHtml()}</title>"))
assertTrue(htmlContent.contains("<h1>${tempDir.name.escapeHtml()}</h1>"))

assertTrue(File(subdir, "index.html").exists())
assertFalse(File(gitDir, "index.html").exists())
}
Expand Down Expand Up @@ -466,7 +484,12 @@ class MainTest {

go(tempDir.absolutePath, -1)

assertTrue(File(tempDir, "index.html").exists())
val indexFile = File(tempDir, "index.html")
assertTrue(indexFile.exists())
val htmlContent = indexFile.readText()
assertTrue(htmlContent.contains("<title>${tempDir.name.escapeHtml()}</title>"))
assertTrue(htmlContent.contains("<h1>${tempDir.name.escapeHtml()}</h1>"))

assertTrue(File(unreadableDir, "index.html").exists())
} finally {
unreadableDir.setReadable(true, false)
Expand All @@ -488,7 +511,12 @@ class MainTest {
val cli = Html4tree()
cli.parse(arrayOf(tempDir.absolutePath))
main(arrayOf(tempDir.absolutePath))
assertTrue(File(tempDir, "index.html").exists())

val indexFile = File(tempDir, "index.html")
assertTrue(indexFile.exists())
val htmlContent = indexFile.readText()
assertTrue(htmlContent.contains("<title>${tempDir.name.escapeHtml()}</title>"))
assertTrue(htmlContent.contains("<h1>${tempDir.name.escapeHtml()}</h1>"))
}

@Test(expected = IllegalArgumentException::class)
Expand Down Expand Up @@ -520,6 +548,21 @@ class MainTest {
process_dir(tempDir)
}

@Test
fun testProcessDirEmptyNameFallback() {
val fakeRoot = object : File(tempDir, "fakeRoot") {
override fun getName(): String = ""
}
fakeRoot.mkdir()
process_dir(fakeRoot)
val indexFile = File(fakeRoot, "index.html")
assertTrue(indexFile.exists())
val htmlContent = indexFile.readText()
val expectedFallback = fakeRoot.absolutePath.escapeHtml()
assertTrue(htmlContent.contains("<title>$expectedFallback</title>"))
assertTrue(htmlContent.contains("<h1>$expectedFallback</h1>"))
}

@Test(expected = IllegalArgumentException::class)
fun testGoBlankDir() {
go(" ", -1)
Expand Down
Loading