Improve definition readouts

main
Elnu 2 years ago
parent b5b45cc4af
commit b99ebc787d

@ -36,7 +36,7 @@ type Entry struct {
type Definition struct {
Definition string
PartOfSpeech string
PartOfSpeech []string
}
func ParseEntry(entry jmdict.JmdictEntry) Entry {
@ -49,17 +49,17 @@ func ParseEntry(entry jmdict.JmdictEntry) Entry {
reading = entry.Readings[0].Reading
}
var definitions []Definition
if len(entry.Sense) > 0 && len(entry.Sense[0].Glossary) > 0 {
definitions = make([]Definition, len(entry.Sense[0].Glossary))
for i, glossary := range entry.Sense[0].Glossary {
var pos string
if len(entry.Sense[0].PartsOfSpeech) > i+1 {
pos = entry.Sense[0].PartsOfSpeech[i]
definitions = make([]Definition, len(entry.Sense))
for i, sense := range entry.Sense {
definition := sense.Glossary[0].Content
if len(sense.Glossary) > 1 {
for _, glossary := range sense.Glossary[1:] {
definition += "; " + glossary.Content
}
definitions[i] = Definition{
Definition: glossary.Content,
PartOfSpeech: pos,
}
definitions[i] = Definition{
Definition: definition,
PartOfSpeech: sense.PartsOfSpeech,
}
}
return Entry{

@ -5,6 +5,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jidict</title>
<link rel="stylesheet" href="https://unpkg.com/missing.css@1.0.9/dist/missing.min.css">
<style>
li {
margin-top: 0.75em;
}
</style>
<script src="https://unpkg.com/htmx.org@1.9.3"></script>
</head>
<body>

@ -1,3 +1,3 @@
{{ define "definition" }}
{{ if .PartOfSpeech }}<chip>{{ .PartOfSpeech }}</chip> {{ end }}{{ .Definition -}}
{{- define "definition" -}}
{{ if .PartOfSpeech }}<small><chip>{{ .PartOfSpeech }}</chip></small><br>{{ end }}{{ .Definition -}}
{{ end }}

@ -1,5 +1,5 @@
<p><i>{{ $count := (len .) }}{{ if eq $count 0 }}No results{{ else }}{{ $count }} result{{ if ne $count 1}}s{{ end }}{{ end }}.</i></p>
{{- range . -}}
{{ range . -}}
<div class="box">
<h3>
{{- if .Kanji -}}
@ -13,7 +13,9 @@
{{- else -}}
<ol>
{{- range .Definitions }}
<li>{{- template "definition" . -}}</li>
<li>
{{ template "definition" . }}
</li>
{{- end }}
</ol>
{{- end }}