diff --git a/src/components/Article.vue b/src/components/Article.vue index 1f3808011f941f6ddb2f10a372a9aa8ae7eeeeda..954dfcadc546bc9587d908d131471fbf6fc1fb16 100644 --- a/src/components/Article.vue +++ b/src/components/Article.vue @@ -42,6 +42,8 @@ import Header from './Header.vue' import ArticleFooter from './ArticleFooter.vue' import InflectionButton from './InflectionButton.vue' +import entities from '../utils/entities.js' + function find_sub_articles(definition) { let sub_art_list = [] let sub_definitions = definition.elements.filter(el => el.type_ == 'definition') @@ -84,14 +86,8 @@ export default { computed: { snippet: function() { - let text = "" - - this.article.body.definitions.forEach((definition) => { - //console.log(definition) - text+=definition.elements[0].content - }) - return text + return this.parse_definitions(this.article.body.definitions) }, collapsable: function() { @@ -129,6 +125,54 @@ export default { InflectionButton }, methods: { + parse_definitions: function(node) { + console.log(node) + //console.log(entities["nn"]["overf"]) + + let definitionTexts = [] + + node.forEach((definition) => { + if (definition.elements[0].content) { + let new_string = "" + let old_parts = definition.elements[0].content.split(/(\$)/) + let linkIndex = 0 + old_parts.forEach((item) => { + if (item == '$') { + if (definition.elements[0].items[linkIndex].id) { + new_string += entities[this.dictionary][definition.elements[0].items[linkIndex].id].expansion + } + else { + new_string += definition.elements[0].items[linkIndex].lemmas[0].lemma + + } + + if (!definition.elements[0].items[linkIndex].id) { + console.log("NO", definition.elements[0].items[linkIndex]) + } + linkIndex += 1 + } + else { + console.log(item) + new_string += item + } + + }) + console.log("STRING", new_string) + console.log("LAST", new_string.substring(new_string.length, new_string.length - 1)) + if (new_string.substring(new_string.length, new_string.length - 1) == ":") { + new_string = new_string.slice(0, -1)+"[...]" + } + definitionTexts.push(new_string) + + } + else if (definition.elements[0].elements) { + definitionTexts.push(this.parse_definitions(definition.elements)) + } + }) + + return definitionTexts.join(" [...] ") + + }, expand: function() { if (this.collapsed) { this.collapsed = false diff --git a/src/components/Header.vue b/src/components/Header.vue index 57fb7d99c3157b06729b01d1d2fec20ac13bd9b4..d3afe93f5da38fd5d6e0565539e8f492e178fcd4 100644 --- a/src/components/Header.vue +++ b/src/components/Header.vue @@ -22,7 +22,7 @@ </v-menu>) </span> <span v-if="$parent.collapsed && $parent.has_content" class="definition_snippet"> - - {{$parent.snippet}} + | {{$parent.snippet}} </span> <span v-if="$parent.collapsable" > <v-btn class="expand_icon" :title="$parent.collapsed? 'Vis mer' : 'Kollaps'"