<template> <article v-if="article" :class="dictionary"> <Header :lemmas="article.lemmas" :dictionary="dictionary" :article_id="article.article_id" /> <div class="article_content" :class="$vuetify.breakpoint.name"> <section v-if="article.body.pronunciation && article.body.pronunciation.length" class="pronunciation"> <h3>Uttale</h3> <ul> <DefElement v-for="(element, index) in article.body.pronunciation" :dictionary="dictionary" :key="index" :body='element' @article-click="article_link_click" /> </ul> </section> <section v-if="article.body.etymology && article.body.etymology.length" class="etymology"> <h3>Opphav</h3> <ul> <DefElement v-for="(element, index) in article.body.etymology" :dictionary="dictionary" :key="index" :body='element' @article-click="article_link_click" /> </ul> </section> <section class="definitions" v-if="has_content"> <h3>{{def_label}}</h3> <ol> <Definition v-for="definition in article.body.definitions" :dictionary="dictionary" :level="1" :key="definition.id" :body='definition' @article-click="article_link_click" /> </ol> </section> <section v-if="sub_articles.length" class="expressions"> <h3>Faste uttrykk</h3> <ul> <SubArticle :body="subart" v-for="(subart, index) in sub_articles" :dictionary="dictionary" :key="index" @article-click="article_link_click" /> </ul> </section> <div class="fade"> <router-link :to="link_to_self.ref" @click.native="details_click(link_to_self)"> Velg <img class="nav_arrow" src="../assets/arrow_right.svg"> </router-link> </div> </div> <ArticleFooter :article="article"/> </article> </template> <script src="/dist/vue-social-sharing.js"></script> <script> import DefElement from './DefElement.vue' import Definition from './Definition.vue' import SubArticle from './SubArticle.vue' import Header from './Header.vue' import ArticleFooter from './ArticleFooter.vue' function find_sub_articles(definition) { let sub_art_list = [] let sub_definitions = definition.elements.filter(el => el.type_ == 'definition') sub_definitions.forEach((subdef, i) => { sub_art_list = sub_art_list.concat(find_sub_articles(subdef)) }) let sub_articles = definition.elements.filter(el => el.type_ == 'sub_article') sub_art_list = sub_art_list.concat(sub_articles) return sub_art_list } function find_content(definition) { let content_list = [] let sub_definitions = definition.elements.filter(el => el.type_ == 'definition') sub_definitions.forEach((subdef, i) => { content_list = content_list.concat(find_content(subdef)) }) let content_nodes = definition.elements.filter(el => ['explanation', 'example', 'compound_list'].includes(el.type_)) content_list = content_list.concat(content_nodes) return content_list } export default { name: 'Article', props: { article: Object }, computed: { link_to_self: function() { return { ref: '/' + this.dictionary + '/' + this.article.article_id + '/' + encodeURIComponent(this.article.lemmas[0].lemma), article: this.article } }, dictionary: function() { return this.article.dictionary }, def_label: function() { return this.dictionary == 'bob' ? 'Betydning og bruk' : 'Tyding og bruk' }, example_label: function() { return this.dictionary == 'bob' ? 'Eksempel' : 'Døme' }, sub_articles: function() { return this.article.body.definitions.reduce((acc, val) => acc.concat(find_sub_articles(val)), []).sort((s1, s2) => s1.lemmas[0].localeCompare(s2.lemmas[0])) }, has_content: function() { return this.article.body.definitions.reduce((acc, val) => acc.concat(find_content(val)), []).length > 0 } }, components: { DefElement, Definition, SubArticle, Header, ArticleFooter }, methods: { article_link_click: function(item) { this.$emit('article-click', item) }, details_click: function(item) { this.$emit('details-click', item) } } } </script> <style> article { position: relative; padding: 24px; margin: 10px; border-radius: 30px; border: solid 1px var(--v-primary-base); background-color: var(--v-tertiary-base); } #single_article_container article { border-style: none; } .fade { display: none; } section { padding-top: 1em; } h3 { color: #560027; font-variant: small-caps; } section.etymology > h3, section.pronunciation > h3 { display: inline; font-size: 14px; font-variant: revert; } section.etymology ul, section.pronunciation ul, section.etymology li, section.pronunciation li { display: inline; } section.etymology li:not(:first-child):not(:last-child):before, section.pronunciation li:not(:first-child):not(:last-child):before { content: ", "; } section.etymology li:not(:first-child):last-child:before, section.pronunciation li:not(:first-child):last-child:before { content: " eller "; font-style: italic; font-size: smaller; } li { padding-bottom: 4px; } li.level1.definition { list-style: upper-alpha; } li.level2.definition { list-style: decimal; } li.level3.definition { /* Norsk ordbok skal ha "lower.alpha" her */ list-style: disc; } li.sub_article > ul { padding-left: 0px; } ::marker { font-weight: bold; color: var(--v-primary-base); } ol > li:only-child.level1, li:only-child.level2 { /* level3 a.k.a. underdefinisjoner skal vises med bullet selv om de står alene */ list-style: none; } li:only-child.level1 > ol { padding-left: 0px; } ul, ol { padding-left: 12px !important; } ul li { list-style:none; } ul li.definition { list-style: disc; } .fade .nav_arrow { vertical-align: sub; } </style>