Updating kanji display
This commit is contained in:
parent
a9e86544c1
commit
29135ff84f
@ -65,11 +65,12 @@ class Dictionary {
|
||||
for (let name in this.kanjiDicts) {
|
||||
const def = this.kanjiDicts[name].c[kanji];
|
||||
if (def) {
|
||||
const [k, o, ...g] = def;
|
||||
const [k, o, t, ...g] = def;
|
||||
results.push({
|
||||
character: kanji,
|
||||
kunyomi: k.split(' '),
|
||||
onyomi: o.split(' '),
|
||||
tags: t.split(' '),
|
||||
glossary: g
|
||||
});
|
||||
}
|
||||
|
@ -37,30 +37,26 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
|
||||
},"4":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
|
||||
return " <dt>Meanings</dt>\n <dd>\n"
|
||||
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </dd>\n";
|
||||
},"5":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
|
||||
return " "
|
||||
+ container.escapeExpression(container.lambda(depth0, depth0))
|
||||
+ ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(6, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n";
|
||||
},"6":function(container,depth0,helpers,partials,data) {
|
||||
},"5":function(container,depth0,helpers,partials,data) {
|
||||
return ", ";
|
||||
},"8":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
},"7":function(container,depth0,helpers,partials,data) {
|
||||
var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
|
||||
|
||||
return " <dt>Kun'yomi</dt>\n <dd class=\"kanji-reading\">\n"
|
||||
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </dd>\n";
|
||||
},"10":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
|
||||
return " <dt>On'yomi</dt>\n <dd class=\"kanji-reading\">\n"
|
||||
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(5, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </dd>\n";
|
||||
return " <span class=\"tag tag-"
|
||||
+ alias4(((helper = (helper = helpers["class"] || (depth0 != null ? depth0["class"] : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"class","hash":{},"data":data}) : helper)))
|
||||
+ "\" title=\""
|
||||
+ alias4(((helper = (helper = helpers.desc || (depth0 != null ? depth0.desc : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"desc","hash":{},"data":data}) : helper)))
|
||||
+ "\">"
|
||||
+ alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper)))
|
||||
+ "</span>\n";
|
||||
},"9":function(container,depth0,helpers,partials,data) {
|
||||
return " <li><span>"
|
||||
+ container.escapeExpression(container.lambda(depth0, depth0))
|
||||
+ "</span></li>\n";
|
||||
},"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
||||
var stack1, helper, alias1=depth0 != null ? depth0 : {};
|
||||
|
||||
@ -68,13 +64,15 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
|
||||
+ ((stack1 = helpers["with"].call(alias1,(depth0 != null ? depth0.options : depth0),{"name":"with","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n <div class=\"kanji-glyph\">"
|
||||
+ container.escapeExpression(((helper = (helper = helpers.character || (depth0 != null ? depth0.character : depth0)) != null ? helper : helpers.helperMissing),(typeof helper === "function" ? helper.call(alias1,{"name":"character","hash":{},"data":data}) : helper)))
|
||||
+ "</div>\n\n <div class=\"kanji-info\">\n <dl>\n"
|
||||
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.glossary : depth0),{"name":"if","hash":{},"fn":container.program(4, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n"
|
||||
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"if","hash":{},"fn":container.program(8, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n"
|
||||
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"if","hash":{},"fn":container.program(10, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </dl>\n </div>\n</div>\n";
|
||||
+ "</div>\n\n <div class=\"kanji-reading\">\n <table>\n <tr>\n <th>Kunyomi:</th>\n <td>\n"
|
||||
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.kunyomi : depth0),{"name":"each","hash":{},"fn":container.program(4, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </td>\n </tr>\n <tr>\n <th>Onyomi:</th>\n <td>\n"
|
||||
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.onyomi : depth0),{"name":"each","hash":{},"fn":container.program(4, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </td>\n </tr>\n </table>\n </div>\n\n <div class=\"kanji-tags\">\n"
|
||||
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(7, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </div>\n\n <div class=\"kanji-glossary\">\n <ol>\n"
|
||||
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(9, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </ol>\n </div>\n</div>\n";
|
||||
},"useData":true,"useDepths":true});
|
||||
templates['kanji-link.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
|
||||
var helper;
|
||||
@ -146,26 +144,14 @@ templates['term.html'] = template({"1":function(container,depth0,helpers,partial
|
||||
},"11":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
|
||||
return " <div class=\"term-rules\">\n"
|
||||
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.rules : depth0),{"name":"each","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </div>\n";
|
||||
},"12":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
|
||||
return " <span class=\"rule\">"
|
||||
+ container.escapeExpression(container.lambda(depth0, depth0))
|
||||
+ "</span> "
|
||||
+ ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(13, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ ((stack1 = helpers.unless.call(depth0 != null ? depth0 : {},(data && data.last),{"name":"unless","hash":{},"fn":container.program(12, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n";
|
||||
},"13":function(container,depth0,helpers,partials,data) {
|
||||
},"12":function(container,depth0,helpers,partials,data) {
|
||||
return "«";
|
||||
},"15":function(container,depth0,helpers,partials,data) {
|
||||
var stack1;
|
||||
|
||||
return " <div class=\"term-tags\">\n"
|
||||
+ ((stack1 = helpers.each.call(depth0 != null ? depth0 : {},(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(16, data, 0),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </div>\n";
|
||||
},"16":function(container,depth0,helpers,partials,data) {
|
||||
},"14":function(container,depth0,helpers,partials,data) {
|
||||
var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
|
||||
|
||||
return " <span class=\"tag tag-"
|
||||
@ -175,7 +161,7 @@ templates['term.html'] = template({"1":function(container,depth0,helpers,partial
|
||||
+ "\">"
|
||||
+ alias4(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : alias2),(typeof helper === alias3 ? helper.call(alias1,{"name":"name","hash":{},"data":data}) : helper)))
|
||||
+ "</span>\n";
|
||||
},"18":function(container,depth0,helpers,partials,data) {
|
||||
},"16":function(container,depth0,helpers,partials,data) {
|
||||
return " <li><span>"
|
||||
+ container.escapeExpression(container.lambda(depth0, depth0))
|
||||
+ "</span></li>\n";
|
||||
@ -186,12 +172,12 @@ templates['term.html'] = template({"1":function(container,depth0,helpers,partial
|
||||
+ ((stack1 = helpers["with"].call(alias1,(depth0 != null ? depth0.options : depth0),{"name":"with","hash":{},"fn":container.program(1, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n"
|
||||
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.reading : depth0),{"name":"if","hash":{},"fn":container.program(6, data, 0, blockParams, depths),"inverse":container.program(9, data, 0, blockParams, depths),"data":data})) != null ? stack1 : "")
|
||||
+ "\n"
|
||||
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.rules : depth0),{"name":"if","hash":{},"fn":container.program(11, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n"
|
||||
+ ((stack1 = helpers["if"].call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"if","hash":{},"fn":container.program(15, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n <div class=\"term-glossary\">\n <ol>\n"
|
||||
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(18, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ "\n <div class=\"term-rules\">\n"
|
||||
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.rules : depth0),{"name":"each","hash":{},"fn":container.program(11, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </div>\n\n <div class=\"term-tags\">\n"
|
||||
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.tags : depth0),{"name":"each","hash":{},"fn":container.program(14, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </div>\n\n <div class=\"term-glossary\">\n <ol>\n"
|
||||
+ ((stack1 = helpers.each.call(alias1,(depth0 != null ? depth0.glossary : depth0),{"name":"each","hash":{},"fn":container.program(16, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "")
|
||||
+ " </ol>\n </div>\n</div>\n";
|
||||
},"useData":true,"useDepths":true});
|
||||
templates['term-list.html'] = template({"1":function(container,depth0,helpers,partials,data,blockParams,depths) {
|
||||
|
@ -148,7 +148,7 @@ class Translator {
|
||||
}
|
||||
}
|
||||
|
||||
return definitions;
|
||||
return this.processKanji(definitions);
|
||||
}
|
||||
|
||||
processTerm(groups, source, tags, rules=[], root='') {
|
||||
@ -227,6 +227,39 @@ class Translator {
|
||||
}
|
||||
}
|
||||
|
||||
processKanji(entries) {
|
||||
const results = [];
|
||||
for (let entry of entries) {
|
||||
const tagItems = [];
|
||||
for (let tag of entry.tags) {
|
||||
const tagItem = {
|
||||
class: 'default',
|
||||
order: Number.MAX_SAFE_INTEGER,
|
||||
name: tag
|
||||
};
|
||||
|
||||
const tagMeta = this.tagMeta[tag];
|
||||
if (tagMeta) {
|
||||
for (const tagProp in tagMeta) {
|
||||
tagItem[tagProp] = tagMeta[tagProp] || tagItem[tagProp];
|
||||
}
|
||||
}
|
||||
|
||||
tagItems.push(tagItem);
|
||||
}
|
||||
|
||||
results.push({
|
||||
character: entry.character,
|
||||
kunyomi: entry.kunyomi,
|
||||
onyomi: entry.onyomi,
|
||||
tags: tagItems,
|
||||
glossary: entry.glossary
|
||||
});
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
static isKanji(c) {
|
||||
const code = c.charCodeAt(0);
|
||||
return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0;
|
||||
|
@ -106,7 +106,7 @@ body {
|
||||
}
|
||||
|
||||
.term-glossary ol {
|
||||
padding-left: 1.2em;
|
||||
padding-left: 1.4em;
|
||||
}
|
||||
|
||||
.term-glossary li {
|
||||
@ -120,28 +120,36 @@ body {
|
||||
/* kanji styles */
|
||||
|
||||
.kanji-glyph {
|
||||
float: right;
|
||||
font-family: kanji-stroke-orders;
|
||||
font-size: 140px;
|
||||
line-height: 140px;
|
||||
font-size: 120px;
|
||||
line-height: 120px;
|
||||
padding: 0.01em;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.kanji-reading {
|
||||
.kanji-reading table {
|
||||
padding: 0.3em, 0.3em;
|
||||
}
|
||||
|
||||
.kanji-reading th {
|
||||
color: #777;
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.kanji-reading td {
|
||||
font-family: vl-gothic-regular;
|
||||
}
|
||||
|
||||
.kanji-info {
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
.kanji-glossary ol {
|
||||
padding-left: 1.4em;
|
||||
}
|
||||
|
||||
.kanji-info dt {
|
||||
.kanji-glossary li {
|
||||
color: #777;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.kanji-info dd {
|
||||
margin-left: 1.2em;
|
||||
.kanji-glossary li span {
|
||||
color: #000;
|
||||
}
|
||||
|
@ -9,34 +9,38 @@
|
||||
|
||||
<div class="kanji-glyph">{{character}}</div>
|
||||
|
||||
<div class="kanji-info">
|
||||
<dl>
|
||||
{{#if glossary}}
|
||||
<dt>Meanings</dt>
|
||||
<dd>
|
||||
{{#each glossary}}
|
||||
{{.}}{{#unless @last}}, {{/unless}}
|
||||
{{/each}}
|
||||
</dd>
|
||||
{{/if}}
|
||||
|
||||
{{#if kunyomi}}
|
||||
<dt>Kun'yomi</dt>
|
||||
<dd class="kanji-reading">
|
||||
<div class="kanji-reading">
|
||||
<table>
|
||||
<tr>
|
||||
<th>Kunyomi:</th>
|
||||
<td>
|
||||
{{#each kunyomi}}
|
||||
{{.}}{{#unless @last}}, {{/unless}}
|
||||
{{/each}}
|
||||
</dd>
|
||||
{{/if}}
|
||||
|
||||
{{#if onyomi}}
|
||||
<dt>On'yomi</dt>
|
||||
<dd class="kanji-reading">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Onyomi:</th>
|
||||
<td>
|
||||
{{#each onyomi}}
|
||||
{{.}}{{#unless @last}}, {{/unless}}
|
||||
{{/each}}
|
||||
</dd>
|
||||
{{/if}}
|
||||
</dl>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div class="kanji-tags">
|
||||
{{#each tags}}
|
||||
<span class="tag tag-{{class}}" title="{{desc}}">{{name}}</span>
|
||||
{{/each}}
|
||||
</div>
|
||||
|
||||
<div class="kanji-glossary">
|
||||
<ol>
|
||||
{{#each glossary}}
|
||||
<li><span>{{.}}</span></li>
|
||||
{{/each}}
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -17,21 +17,17 @@
|
||||
<div class="term-expression">{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if rules}}
|
||||
<div class="term-rules">
|
||||
{{#each rules}}
|
||||
<span class="rule">{{.}}</span> {{#unless @last}}«{{/unless}}
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
{{#if tags}}
|
||||
<div class="term-tags">
|
||||
{{#each tags}}
|
||||
<span class="tag tag-{{class}}" title="{{desc}}">{{name}}</span>
|
||||
{{/each}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
<div class="term-glossary">
|
||||
<ol>
|
||||
|
Loading…
Reference in New Issue
Block a user