Improve definition readouts

main
Elnu 2 years ago
parent b5b45cc4af
commit b99ebc787d

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

@ -5,6 +5,11 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>jidict</title> <title>jidict</title>
<link rel="stylesheet" href="https://unpkg.com/missing.css@1.0.9/dist/missing.min.css"> <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> <script src="https://unpkg.com/htmx.org@1.9.3"></script>
</head> </head>
<body> <body>

@ -1,3 +1,3 @@
{{ define "definition" }} {{- define "definition" -}}
{{ if .PartOfSpeech }}<chip>{{ .PartOfSpeech }}</chip> {{ end }}{{ .Definition -}} {{ if .PartOfSpeech }}<small><chip>{{ .PartOfSpeech }}</chip></small><br>{{ end }}{{ .Definition -}}
{{ end }} {{ 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> <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"> <div class="box">
<h3> <h3>
{{- if .Kanji -}} {{- if .Kanji -}}
@ -13,7 +13,9 @@
{{- else -}} {{- else -}}
<ol> <ol>
{{- range .Definitions }} {{- range .Definitions }}
<li>{{- template "definition" . -}}</li> <li>
{{ template "definition" . }}
</li>
{{- end }} {{- end }}
</ol> </ol>
{{- end }} {{- end }}