Skip to content

Commit 513c364

Browse files
committed
Db to markdown migration
1 parent 8a59aa3 commit 513c364

36 files changed

Lines changed: 1450 additions & 1506 deletions

File tree

android/build.gradle.kts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ dependencies {
2727
androidTestImplementation(libs.androidx.ui.test.junit4)
2828
debugImplementation(libs.androidx.ui.test.manifest)
2929
debugImplementation(libs.androidx.ui.tooling)
30-
implementation(libs.multiplatform.markdown.renderer.android)
31-
implementation(libs.multiplatform.markdown.renderer.m2)
32-
implementation(libs.multiplatform.markdown.renderer.code)
3330
}
3431

3532
android {
929 KB
Binary file not shown.

android/src/main/java/com/inspiredandroid/linuxcommandbibliotheca/ExtensionFunctions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import androidx.navigation.NavBackStackEntry
44

55
fun NavBackStackEntry.getCategoryId(): String? {
66
return arguments?.getString("categoryId")?.takeIf { it.isNotEmpty() }
7-
?: arguments?.getString("categoryName") // For deep links
7+
?: arguments?.getString("categoryName") // For deep links
88
}
Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
package com.inspiredandroid.linuxcommandbibliotheca.data
22

33
data class BasicCategory(
4-
val id: String, // filename without .md (e.g., "filesfolders")
5-
val title: String // from H1 (e.g., "Files & Folders")
4+
/** filename without .md (e.g., "filesfolders") */
5+
val id: String,
6+
/** from H1 (e.g., "Files & Folders") */
7+
val title: String,
68
)
79

810
data class BasicGroup(
9-
val id: Long, // hash of categoryId+description
10-
val description: String // from H2 (e.g., "Create file")
11+
/** hash of categoryId+description */
12+
val id: Long,
13+
/** from H2 (e.g., "Create file") */
14+
val description: String,
1115
)
1216

1317
data class BasicCommand(
14-
val id: Long, // hash for stable ID
15-
val command: String, // e.g., "$ touch [fileName]"
16-
val mans: String // e.g., "touch"
18+
/** hash for stable ID */
19+
val id: Long,
20+
/** e.g., "$ touch [fileName]" */
21+
val command: String,
22+
/** e.g., "touch" */
23+
val mans: String,
1724
)

android/src/main/java/com/inspiredandroid/linuxcommandbibliotheca/data/BasicsRepository.kt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ class BasicsRepository(private val context: Context) {
2222
.sortedBy { it.title }
2323
}
2424

25-
private fun readCategoryTitle(filename: String): String? {
26-
return try {
27-
context.assets.open("basics/$filename").bufferedReader().useLines { lines ->
28-
lines.firstOrNull { it.startsWith("# ") }?.removePrefix("# ")?.trim()
29-
}
30-
} catch (e: Exception) {
31-
null
25+
private fun readCategoryTitle(filename: String): String? = try {
26+
context.assets.open("basics/$filename").bufferedReader().useLines { lines ->
27+
lines.firstOrNull { it.startsWith("# ") }?.removePrefix("# ")?.trim()
3228
}
29+
} catch (e: Exception) {
30+
null
3331
}
3432

3533
fun getGroupsAndCommands(categoryId: String): Pair<List<BasicGroup>, Map<Long, List<BasicCommand>>> {
@@ -57,7 +55,7 @@ class BasicsRepository(private val context: Context) {
5755
val (command, mans) = parseCommandLine(line)
5856
val commandId = (categoryId + currentGroupId + commandIndex).hashCode().toLong()
5957
commandsByGroupId[currentGroupId]?.add(
60-
BasicCommand(id = commandId, command = command, mans = mans)
58+
BasicCommand(id = commandId, command = command, mans = mans),
6159
)
6260
commandIndex++
6361
}

android/src/main/java/com/inspiredandroid/linuxcommandbibliotheca/data/CommandModels.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package com.inspiredandroid.linuxcommandbibliotheca.data
22

33
data class CommandInfo(
4-
val id: Long, // name.hashCode().toLong() for stable ID
5-
val name: String, // filename without .md
4+
/** name.hashCode().toLong() for stable ID */
5+
val id: Long,
6+
/** filename without .md */
7+
val name: String,
68
)
79

810
data class CommandSectionInfo(
9-
val id: Long, // (commandName + title).hashCode().toLong()
10-
val title: String, // "TLDR", "SYNOPSIS", etc.
11+
/** (commandName + title).hashCode().toLong() */
12+
val id: Long,
13+
/** "TLDR", "SYNOPSIS", etc. */
14+
val title: String,
1115
val content: String,
1216
)
1317

android/src/main/java/com/inspiredandroid/linuxcommandbibliotheca/data/CommandsRepository.kt

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,21 @@ class CommandsRepository(private val context: Context) {
3333

3434
return commands
3535
.filter { it.name.lowercase().contains(lowerQuery) }
36-
.sortedWith(compareBy(
37-
// Exact match first
38-
{ it.name.lowercase() != lowerQuery },
39-
// Starts with query second
40-
{ !it.name.lowercase().startsWith(lowerQuery) },
41-
// Then alphabetically
42-
{ it.name }
43-
))
36+
.sortedWith(
37+
compareBy(
38+
// Exact match first
39+
{ it.name.lowercase() != lowerQuery },
40+
// Starts with query second
41+
{ !it.name.lowercase().startsWith(lowerQuery) },
42+
// Then alphabetically
43+
{ it.name },
44+
),
45+
)
4446
}
4547

46-
fun getCommand(name: String): CommandInfo? {
47-
return getCommands().find { it.name == name }
48-
}
48+
fun getCommand(name: String): CommandInfo? = getCommands().find { it.name == name }
4949

50-
fun hasCommand(name: String): Boolean {
51-
return getCommands().any { it.name == name }
52-
}
50+
fun hasCommand(name: String): Boolean = getCommands().any { it.name == name }
5351

5452
fun getSections(commandName: String): List<CommandSectionInfo> {
5553
val sections = mutableListOf<CommandSectionInfo>()
@@ -70,7 +68,7 @@ class CommandsRepository(private val context: Context) {
7068
id = (commandName + currentTitle).hashCode().toLong(),
7169
title = currentTitle,
7270
content = currentContent.toString().trim(),
73-
)
71+
),
7472
)
7573
}
7674
// Start new section
@@ -88,7 +86,7 @@ class CommandsRepository(private val context: Context) {
8886
id = (commandName + currentTitle).hashCode().toLong(),
8987
title = currentTitle,
9088
content = currentContent.toString().trim(),
91-
)
89+
),
9290
)
9391
}
9492
} catch (e: Exception) {

0 commit comments

Comments
 (0)