NewsArticles.vue 4.64 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<template>

  <div class="news-article">
    <article class="news" :id="article.id" v-for="article in articles" v-bind:key="article.id">
      <a class="title" :href="'#' + article.id">{{ article.title }}</a>

      <div class="under-title">
        <span class="dt-published">{{ article.date.toLocaleDateString() }}</span>

        <span v-if="article.mastodon">·</span>
        <a v-if="article.mastodon" :title="getMastodonTootTitle()" :href="article.mastodon" target="_blank">
          <i class="fa fa-mastodon" aria-hidden="true"></i>
        </a>

        <span v-if="article.twitter">·</span>
        <a v-if="article.twitter" :title="getTwitterTweetTitle()" :href="article.twitter" target="_blank">
          <i class="fa fa-twitter" aria-hidden="true"></i>
        </a>
      </div>

      <div class="body" v-on:click="onNewsClick($event)" v-html="article.html"></div>
    </article>

    <div id="modal" @click="closeModal()" v-bind:class="{ 'hide-modal': hideModal }">
      <img loading="lazy" :src="modalImgSrc" />

      <div class="caption">{{ modalCaption }}</div>
    </div>
  </div>
</template>

<style lang="scss">
  @import '../scss/_variables.scss';
Chocobozzz's avatar
Chocobozzz committed
34
  @import '../scss/_mixins.scss';
35
36
37
38
39
40

  .news-article {
    p {
      margin-bottom: 10px;
    }

Chocobozzz's avatar
Chocobozzz committed
41
42
    p + *:not(ul),
    ul + *:not(ul) {
43
44
45
46
47
48
49
50
51
52
53
      margin-top: 1em;
    }

    .news {
      padding: 40px 50px;
      border: solid 1px #d9d9d9;
      border-left: 6px solid $orange;
      box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.35);
      margin-bottom: 60px;

      .title {
Chocobozzz's avatar
Chocobozzz committed
54
55
56
        @include proza-semi-bold;

        font-size: 32px;
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
        color: #000 !important;
      }

      .under-title {
        font-size: 16px;
        color: #70767d !important;

        span:not(:first-of-type),
        a {
          margin-left: .5rem;
          color: #70767d !important;
        }
      }

      .body {
        margin-top: 40px;
      }

      a {
        word-break: break-word;
      }

Chocobozzz's avatar
Chocobozzz committed
79
80
81
82
83
      h3 {
        font-size: 26px;
        margin-top: 1.5em;
      }

84
      img + h4,
Chocobozzz's avatar
Chocobozzz committed
85
86
87
      figure + h4,
      img + h3,
      figure + h3 {
88
89
90
91
        margin-top: 1.2rem;
      }

      img {
Chocobozzz's avatar
Chocobozzz committed
92
        cursor: pointer;
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
        max-width: 100%;
        height: auto;
      }

      figure {
        margin: 30px 0;
        border: 10px solid #fff3ea;
        border-bottom: 0;

        figcaption {
          font-size: 14px;
          background: #fff3ea;
          text-align: center;
          padding: 10px 0;
          margin-top: -10px;
        }
      }

      @media screen and (max-width: $small-screen) {
        padding: 10px;
      }
    }

    #modal {
      &.hide-modal {
        display: none;
      }

      position: fixed;
      z-index: 1;
      padding-top: 5vh;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      overflow: auto;
      background-color: rgb(0, 0, 0);
      background-color: rgba(0, 0, 0, 0.9);

      img {
        margin: auto;
        display: block;
        height: auto;
        width: auto;
        max-height: 90%;
      }

      .caption {
        margin: auto;
        display: block;
        width: 80%;
        max-width: 700px;
        text-align: center;
        color: #ccc;
        padding: 10px;
      }

      img,
      .caption {
        animation-name: zoom;
        animation-duration: 0.6s;
      }
    }
  }
</style>

<script>
  export default {
    components: {
    },

    props: {
      articles: Array
    },

    data: function () {
      return {
        modalImgSrc: '',
        modalCaption: '',
        hideModal: true
      }
    },

    methods: {
      onNewsClick (event) {
        if (event.target instanceof HTMLImageElement) {
          return this.openModal(event)
        }
      },

      openModal: function (event) {
        const img = event.target

        this.hideModal = false
        this.modalImgSrc = img.src
        this.modalCaption = img.alt
      },

      closeModal: function () {
        this.hideModal = true
        this.modalImgSrc = ''
        this.modalCaption = ''
      },

      getNewsletterTitle () {
        return this.$gettext('Subscribe to the newsletter')
      },

      getSyndicationTitle () {
        return this.$gettext('Subscribe to RSS feed')
      },

      getMastodonTitle () {
        return this.$gettext('Subscribe to our Mastodon account')
      },

      getTwitterTitle () {
        return this.$gettext('Subscribe to our Twitter account')
      },

      getMastodonTootTitle () {
        return this.$gettext('Open the Toot')
      },

      getTwitterTweetTitle () {
        return this.$gettext('Open the Tweet')
      }
    },

    metaInfo: function () {
      return {
        title: this.$gettext('News')
      }
    }
  }
</script>