Skip to content

Commit

Permalink
Improve surah list naming and search
Browse files Browse the repository at this point in the history
  • Loading branch information
ngekoding committed Dec 1, 2024
1 parent a6b2ba3 commit 14b9c76
Show file tree
Hide file tree
Showing 5 changed files with 692 additions and 68 deletions.
15 changes: 2 additions & 13 deletions src/components/SurahChangerDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</template>

<script>
import surahList from "src/data/surah-list";
import { getFilteredSurahList } from "src/data/surah-list";
export default {
name: "SurahChangerDialog",
props: {
Expand All @@ -72,7 +72,6 @@ export default {
},
data() {
return {
surahList: surahList,
showDialog: false,
keyword: ""
};
Expand All @@ -97,17 +96,7 @@ export default {
},
computed: {
surahListFiltered() {
if (this.keyword) {
const q = this.keyword.toLowerCase();
return this.surahList.filter(s => {
return (
s.nameSimple.toLowerCase().includes(q) ||
s.nameArabic.toLowerCase().includes(q) ||
s.nameTranslated.toLowerCase().includes(q)
);
});
}
return this.surahList;
return getFilteredSurahList(this.keyword);
}
},
methods: {
Expand Down
122 changes: 81 additions & 41 deletions src/data/surah-list/corrections.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* We make some corrections for the surah list
* E.g. Follows Indonesian Ministry of Religion naming
* by comparing naming from some printed Mushaf, the API and Kemenag
*
* Data structures
* We use surah id as object key for performance access
Expand All @@ -13,75 +13,115 @@
// }

export default {
9: {
nameSimple: "At-Taubah"
1: {
nameTranslated: "Pembukaan"
},
21: {
nameSimple: "Al-Anbiya’"
2: {
nameTranslated: "Sapi Betina"
},
26: {
nameSimple: "Asy-Syu'ara'"
30: {
nameTranslated: "Bangsa Romawi"
},
34: {
nameSimple: "Saba"
nameTranslated: "Kaum Saba'"
},
36: {
nameSimple: "Yasin"
41: {
nameTranslated: "Yang Dijelaskan"
},
42: {
nameSimple: "Asy-Syura"
43: {
nameTranslated: "Perhiasan"
},
44: {
nameTranslated: "Kabut"
},
45: {
nameSimple: "Al-Jasiyah"
nameTranslated: "Yang Berlutut"
},
46: {
nameTranslated: "Bukit-Bukit Pasir"
},
51: {
nameSimple: "Adz-Dzariyat"
nameTranslated: "Angin Yang Menerbangkan"
},
52: {
nameTranslated: "Bukit"
},
55: {
nameTranslated: "Yang Maha Pemurah"
},
58: {
nameSimple: "Al-Mujadalah"
56: {
nameTranslated: "Hari Kiamat"
},
59: {
nameSimple: "Al-Hasyr"
62: {
nameTranslated: "Hari Jum'at"
},
61: {
nameSimple: "Ash-Shaf"
64: {
nameTranslated: "Hari Dinampakkan Kesalahan"
},
66: {
nameTranslated: "Mengharamkan"
},
69: {
nameTranslated: "Hari Kiamat"
},
73: {
nameTranslated: "Orang Yang Berselimut"
},
74: {
nameSimple: "Al-Muddassir"
nameTranslated: "Orang Yang Berkemul"
},
78: {
nameSimple: "An-Naba'"
nameTranslated: "Berita Besar"
},
84: {
nameSimple: "Al-Insyiqaq"
79: {
nameTranslated: "Malaikat Yang Mencabut"
},
88: {
nameSimple: "Al-Gasyiyah"
80: {
nameTranslated: "Bermuka Masam"
},
91: {
nameSimple: "Asy-Syams"
81: {
nameTranslated: "Menggulung"
},
92: {
nameSimple: "Al-Lail"
86: {
nameTranslated: "Yang Datang di Malam Hari"
},
87: {
nameTranslated: "Yang Paling Tinggi"
},
88: {
nameTranslated: "Hari Pembalasan"
},
93: {
nameTranslated: "Waktu Matahari Sepenggalahan Naik"
},
94: {
nameSimple: "Asy-Syarh"
nameTranslated: "Melapangkan"
},
97: {
nameTranslated: "Kemuliaan"
},
98: {
nameTranslated: "Pembuktian"
},
99: {
nameTranslated: "Kegoncangan"
},
101: {
nameTranslated: "Hari Kiamat"
},
102: {
nameSimple: "At-Takasur"
nameTranslated: "Bermegah-Megahan"
},
106: {
nameSimple: "Quraisy"
nameTranslated: "Suku Quraisy"
},
108: {
nameSimple: "Al-Kausar"
107: {
nameTranslated: "Barang-Barang Yang Berguna"
},
111: {
nameArabic: "اللهب",
nameSimple: "Al-Lahab",
nameTranslated: "Gejolak Api"
109: {
nameTranslated: "Orang-Orang Kafir"
},
112: {
nameTranslated: "Ikhlas"
113: {
nameTranslated: "Waktu Subuh"
}
};
35 changes: 32 additions & 3 deletions src/data/surah-list/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import surahListByApi from "./surah-list-by-api";
import surahListKemenag from "./surah-list-kemenag";
import surahListCorrections from "./corrections";
import createFuzzySearch from "@nozbe/microfuzz";
import { normalizeLatinText } from "src/lib/search-helper";

const surahList = [];

surahListByApi.forEach(item => {
const kemenag = surahListKemenag[item.id] ?? null;
const correction = surahListCorrections[item.id] ?? null;

surahList.push({
id: item.id,
versesCount: item.verses_count,
bismillahPre: item.bismillah_pre,
nameArabic: correction?.nameArabic ?? item.name_arabic,
nameSimple: correction?.nameSimple ?? item.name_simple,
nameTranslated: correction?.nameTranslated ?? item.translated_name.name,
nameArabic: correction?.nameArabic ?? kemenag?.nameArabic,
nameSimple: correction?.nameSimple ?? kemenag?.nameSimple,
nameTranslated: correction?.nameTranslated ?? kemenag?.nameTranslated,
pages: item.pages
});
});

const getFilteredSurahList = keyword => {
if (!keyword) {
return surahList;
}

const q = normalizeLatinText(keyword);
const fuzzySearch = createFuzzySearch(surahList, {
getText: item => [item.nameSimple, item.nameArabic, item.nameTranslated]
});

const filtered = fuzzySearch(q).map(item => {
return {
...item.item
};
});

// Keep order
filtered.sort((a, b) => a.id - b.id);

return filtered;
};

export { surahList, getFilteredSurahList };

export default surahList;
Loading

0 comments on commit 14b9c76

Please sign in to comment.