Updating kanji display

This commit is contained in:
Alex Yatskov 2016-08-07 19:56:50 -07:00
parent a9e86544c1
commit 29135ff84f
6 changed files with 123 additions and 95 deletions

View File

@ -65,11 +65,12 @@ class Dictionary {
for (let name in this.kanjiDicts) { for (let name in this.kanjiDicts) {
const def = this.kanjiDicts[name].c[kanji]; const def = this.kanjiDicts[name].c[kanji];
if (def) { if (def) {
const [k, o, ...g] = def; const [k, o, t, ...g] = def;
results.push({ results.push({
character: kanji, character: kanji,
kunyomi: k.split(' '), kunyomi: k.split(' '),
onyomi: o.split(' '), onyomi: o.split(' '),
tags: t.split(' '),
glossary: g glossary: g
}); });
} }

View File

@ -37,30 +37,26 @@ templates['kanji.html'] = template({"1":function(container,depth0,helpers,partia
},"4":function(container,depth0,helpers,partials,data) { },"4":function(container,depth0,helpers,partials,data) {
var stack1; 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 " " return " "
+ container.escapeExpression(container.lambda(depth0, depth0)) + 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"; + "\n";
},"6":function(container,depth0,helpers,partials,data) { },"5":function(container,depth0,helpers,partials,data) {
return ", "; return ", ";
},"8":function(container,depth0,helpers,partials,data) { },"7":function(container,depth0,helpers,partials,data) {
var stack1; 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" return " <span class=\"tag tag-"
+ ((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 : "") + 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)))
+ " </dd>\n"; + "\" title=\""
},"10":function(container,depth0,helpers,partials,data) { + 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)))
var stack1; + "\">"
+ 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)))
return " <dt>On'yomi</dt>\n <dd class=\"kanji-reading\">\n" + "</span>\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 : "") },"9":function(container,depth0,helpers,partials,data) {
+ " </dd>\n"; 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) { },"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data,blockParams,depths) {
var stack1, helper, alias1=depth0 != null ? depth0 : {}; 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 : "") + ((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\">" + "\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))) + 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" + "</div>\n\n <div class=\"kanji-reading\">\n <table>\n <tr>\n <th>Kunyomi:</th>\n <td>\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 : "") + ((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 : "")
+ "\n" + " </td>\n </tr>\n <tr>\n <th>Onyomi:</th>\n <td>\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 : "") + ((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 : "")
+ "\n" + " </td>\n </tr>\n </table>\n </div>\n\n <div class=\"kanji-tags\">\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 : "") + ((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 : "")
+ " </dl>\n </div>\n</div>\n"; + " </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}); },"useData":true,"useDepths":true});
templates['kanji-link.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) { templates['kanji-link.html'] = template({"compiler":[7,">= 4.0.0"],"main":function(container,depth0,helpers,partials,data) {
var helper; var helper;
@ -146,26 +144,14 @@ templates['term.html'] = template({"1":function(container,depth0,helpers,partial
},"11":function(container,depth0,helpers,partials,data) { },"11":function(container,depth0,helpers,partials,data) {
var stack1; 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\">" return " <span class=\"rule\">"
+ container.escapeExpression(container.lambda(depth0, depth0)) + container.escapeExpression(container.lambda(depth0, depth0))
+ "</span> " + "</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"; + "\n";
},"13":function(container,depth0,helpers,partials,data) { },"12":function(container,depth0,helpers,partials,data) {
return "&laquo;"; return "&laquo;";
},"15":function(container,depth0,helpers,partials,data) { },"14":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) {
var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression; var helper, alias1=depth0 != null ? depth0 : {}, alias2=helpers.helperMissing, alias3="function", alias4=container.escapeExpression;
return " <span class=\"tag tag-" 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))) + 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"; + "</span>\n";
},"18":function(container,depth0,helpers,partials,data) { },"16":function(container,depth0,helpers,partials,data) {
return " <li><span>" return " <li><span>"
+ container.escapeExpression(container.lambda(depth0, depth0)) + container.escapeExpression(container.lambda(depth0, depth0))
+ "</span></li>\n"; + "</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 : "") + ((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" + "\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 : "") + ((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" + "\n <div class=\"term-rules\">\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 : "") + ((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 : "")
+ "\n" + " </div>\n\n <div class=\"term-tags\">\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 : "") + ((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 : "")
+ "\n <div class=\"term-glossary\">\n <ol>\n" + " </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(18, data, 0, blockParams, depths),"inverse":container.noop,"data":data})) != null ? stack1 : "") + ((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"; + " </ol>\n </div>\n</div>\n";
},"useData":true,"useDepths":true}); },"useData":true,"useDepths":true});
templates['term-list.html'] = template({"1":function(container,depth0,helpers,partials,data,blockParams,depths) { templates['term-list.html'] = template({"1":function(container,depth0,helpers,partials,data,blockParams,depths) {

View File

@ -148,7 +148,7 @@ class Translator {
} }
} }
return definitions; return this.processKanji(definitions);
} }
processTerm(groups, source, tags, rules=[], root='') { 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) { static isKanji(c) {
const code = c.charCodeAt(0); const code = c.charCodeAt(0);
return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0; return code >= 0x4e00 && code < 0x9fb0 || code >= 0x3400 && code < 0x4dc0;

View File

@ -106,7 +106,7 @@ body {
} }
.term-glossary ol { .term-glossary ol {
padding-left: 1.2em; padding-left: 1.4em;
} }
.term-glossary li { .term-glossary li {
@ -120,28 +120,36 @@ body {
/* kanji styles */ /* kanji styles */
.kanji-glyph { .kanji-glyph {
float: right;
font-family: kanji-stroke-orders; font-family: kanji-stroke-orders;
font-size: 140px; font-size: 120px;
line-height: 140px; line-height: 120px;
padding: 0.01em; padding: 0.01em;
vertical-align: top; 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; font-family: vl-gothic-regular;
} }
.kanji-info { .kanji-glossary ol {
display: block; padding-left: 1.4em;
overflow: hidden;
} }
.kanji-info dt { .kanji-glossary li {
color: #777; color: #777;
font-weight: bold;
} }
.kanji-info dd { .kanji-glossary li span {
margin-left: 1.2em; color: #000;
} }

View File

@ -9,34 +9,38 @@
<div class="kanji-glyph">{{character}}</div> <div class="kanji-glyph">{{character}}</div>
<div class="kanji-info"> <div class="kanji-reading">
<dl> <table>
{{#if glossary}} <tr>
<dt>Meanings</dt> <th>Kunyomi:</th>
<dd> <td>
{{#each glossary}}
{{.}}{{#unless @last}}, {{/unless}}
{{/each}}
</dd>
{{/if}}
{{#if kunyomi}}
<dt>Kun'yomi</dt>
<dd class="kanji-reading">
{{#each kunyomi}} {{#each kunyomi}}
{{.}}{{#unless @last}}, {{/unless}} {{.}}{{#unless @last}}, {{/unless}}
{{/each}} {{/each}}
</dd> </td>
{{/if}} </tr>
<tr>
{{#if onyomi}} <th>Onyomi:</th>
<dt>On'yomi</dt> <td>
<dd class="kanji-reading">
{{#each onyomi}} {{#each onyomi}}
{{.}}{{#unless @last}}, {{/unless}} {{.}}{{#unless @last}}, {{/unless}}
{{/each}} {{/each}}
</dd> </td>
{{/if}} </tr>
</dl> </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>
</div> </div>

View File

@ -17,21 +17,17 @@
<div class="term-expression">{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}</div> <div class="term-expression">{{#kanjiLinks}}{{expression}}{{/kanjiLinks}}</div>
{{/if}} {{/if}}
{{#if rules}}
<div class="term-rules"> <div class="term-rules">
{{#each rules}} {{#each rules}}
<span class="rule">{{.}}</span> {{#unless @last}}&laquo;{{/unless}} <span class="rule">{{.}}</span> {{#unless @last}}&laquo;{{/unless}}
{{/each}} {{/each}}
</div> </div>
{{/if}}
{{#if tags}}
<div class="term-tags"> <div class="term-tags">
{{#each tags}} {{#each tags}}
<span class="tag tag-{{class}}" title="{{desc}}">{{name}}</span> <span class="tag tag-{{class}}" title="{{desc}}">{{name}}</span>
{{/each}} {{/each}}
</div> </div>
{{/if}}
<div class="term-glossary"> <div class="term-glossary">
<ol> <ol>