aboutsummaryrefslogtreecommitdiff
path: root/pages/article.sh
blob: 9832a76ccbbe81214104997d1f50e75fbae9775d (plain)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash

ARTICLE_TITLE=$(basename "$ARTICLE_FILE")

# Pick all file content
ARTICLE_FILE_CONTENT=$(cat "$ARTICLE_FILE")

# The first 3 lines of the file are metadata information
ARTICLE_METADATA=$(echo "$ARTICLE_FILE_CONTENT" | head -n 3)

# Skip file metadata, first 3 lines
ARTICLE_CONTENT=$(echo "$ARTICLE_FILE_CONTENT" | tail -n +3)

# Tags are placed on the first line of the file, delimited by commas
IFS=',' read -ra ARTICLE_TAGS <<< "$(echo "$ARTICLE_METADATA" | head -n 1)"

ARTICLE_TIME=$(stat --format="Criado em: %w<br/>Última atualização: %z" "$ARTICLE_FILE")
ARTICLE_BYTES=$(stat --format="%o bytes" "$ARTICLE_FILE")

if [ $? -gt 0 ]; then
  STATUS=404
  cat <<ERR
<p class="err-404">cat: $ARTICLE_FILE: Arquivo ou diretório inexistente</p>
ERR
  exit 0
fi

cat <<ARTICLE
<article class="container">
  <section>
    <div class="post-header">
      <h4 class="post-title">stat -c "%o %w %z" $ARTICLE_FILE</h4>
      <small>$ARTICLE_BYTES</small> <br/>
      <time>$ARTICLE_TIME</time> <br/>

      <ul class="tags">
        $(
          for i in "${ARTICLE_TAGS[@]}"; do
            echo "<li class="tag">$i</li>"
          done
        )
      </ul>
    </div>

    <div class="post-content">
      <p>
        ${ARTICLE_CONTENT}
      </p>
    </div>
  </section>
</article>
ARTICLE