~mika/www.m1kadev.nl

fabcc85263d719bca97e38a67aa62b608e2bfb7f — m1kadev 6 months ago c6b023f
add ogp support
M .gitignore => .gitignore +1 -2
@@ 1,3 1,2 @@
/build
/static/*.min.*
TODO
\ No newline at end of file
/static/*.min.*
\ No newline at end of file

A TODO => TODO +4 -0
@@ 0,0 1,4 @@
- back button in thought page
- mobile-responsive design
- clean up build.exs
- make m1kadev.nl mark link back to home
\ No newline at end of file

M build.exs => build.exs +66 -5
@@ 47,6 47,18 @@ defmodule Templates do
      :date
    ]
  )

  def ogp(title, url, description) do
    """
      <meta property="og:type" content="website">
      <meta property="og:title" content="#{title}">
      <meta property="og:url" content="#{url}">
      <meta property="og:image" content="https://m1kadev.nl/static/logo.png">
      <meta property="og:description" content="#{description}">
      <meta property="og:locale" content="en_GB" />
      <meta property="og:site_name" content="m1kadev.nl" />
    """
  end
end

defmodule Builders do


@@ 118,7 130,9 @@ defmodule Builders do
            about_paste: "Created on " <> time,
            language: "<script src=\"static/" <> lang <> ".min.js\"></script>",
            codetag: "<pre><code class=\"language-" <> lang <> "\">",
            code: code
            code: code,
            ogp:
              Templates.ogp(file, "https://m1kadev.nl/pastes/#{file}.html", "Created on " <> time)
          },
          bricks
        )


@@ 142,7 156,26 @@ defmodule Builders do

    {content, 0} = System.cmd("fxg", [input_path])

    output = Mustache.render(template, Map.merge(%{fxg_content: content, location: name}, bricks))
    ogp =
      Templates.ogp(
        name,
        "https://m1kadev.nl/#{String.replace_prefix(output_path, "build/", "")}",
        ""
      )

    output =
      Mustache.render(
        template,
        Map.merge(
          %{
            fxg_content: content,
            location: name,
            ogp: ogp
          },
          bricks
        )
      )

    IO.inspect(output_path)
    :ok = File.write(output_path, output)
  end


@@ 254,7 287,13 @@ paste_index =
    main_template,
    Map.merge(bricks, %{
      fxg_content: pastes_header <> "<p>" <> paste_data <> "</p>",
      location: "pastes"
      location: "pastes",
      ogp:
        Templates.ogp(
          "thoughts",
          "https://m1kadev.nl/pastes",
          "random code snippets i found useful or wanted to save :))"
        )
    })
  )



@@ 275,7 314,16 @@ thoughts = Enum.map(thought_paths, fn {path, date} -> Builders.thought(path, dat
thoughts_html =
  Mustache.render(
    thoughts_template,
    Map.merge(bricks, %{fxg_content: Enum.join(thoughts, "<hr>"), location: "thoughts"})
    Map.merge(bricks, %{
      fxg_content: Enum.join(thoughts, "<hr>"),
      location: "thoughts",
      ogp:
        Templates.ogp(
          "thoughts",
          "https://m1kadev.nl/thoughts",
          "important thoughts that needed publishing"
        )
    })
  )

for {thought, {path, time}} <- Enum.zip(thoughts, thought_paths) do


@@ 283,11 331,22 @@ for {thought, {path, time}} <- Enum.zip(thoughts, thought_paths) do
  output_path = "build/thoughts/" <> thought <> ".html"

  when_said = DateTime.from_unix!(time) |> Calendar.strftime("%H:%M, %d/%m/%y")
  thought_txt = File.read!(path)

  thought_html =
    Mustache.render(
      thought_template,
      Map.merge(bricks, %{fxg_content: File.read!(path), thought: thought, date: when_said})
      Map.merge(bricks, %{
        fxg_content: thought_txt,
        thought: thought,
        date: when_said,
        ogp:
          Templates.ogp(
            thought,
            "https://m1kadev.nl/#{String.replace_prefix(output_path, "build/", "")}",
            thought_txt
          )
      })
    )

  File.write(output_path, thought_html)


@@ 295,6 354,8 @@ end

File.write("build/thoughts/index.html", thoughts_html)

File.copy("favicon.ico", "build/favicon.ico")

{:ok, date} = DateTime.now("Europe/Amsterdam")
build_time = Calendar.strftime(date, "%H:%M:%S %d/%m/%y")


A favicon.ico => favicon.ico +0 -0
A static/logo.png => static/logo.png +0 -0
M templates/base.html => templates/base.html +3 -0
@@ 8,6 8,9 @@
    {{ &highlight }}

    <title>{{ location }} - m1kadev</title>

    {{ &ogp }}

</head>

<body>

M templates/pages/colophon.html => templates/pages/colophon.html +3 -0
@@ 7,6 7,9 @@

    <title> {{ location }} - m1kadev.nl</title>

    {{ &ogp }}


</head>

<body>

M templates/pages/index.html => templates/pages/index.html +2 -0
@@ 12,6 12,8 @@
    <link rel="stylesheet" href="/styles/index.css">

    <title>{{ location }} - m1kadev</title>

    {{ &ogp }}
</head>

<body>

M templates/paste.html => templates/paste.html +3 -0
@@ 8,6 8,9 @@
    {{ &highlight }}

    <title>{{ filename }} - m1kadev</title>

    {{ &ogp }}

</head>

<body>

M templates/thought.html => templates/thought.html +3 -0
@@ 8,6 8,9 @@
    <link rel="stylesheet" href="/styles/thought.css">

    <title> {{ thought }} - m1kadev</title>

    {{ &ogp }}

</head>

<body>

M templates/thoughts.html => templates/thoughts.html +3 -0
@@ 10,6 10,9 @@
    <link rel="stylesheet" href="/styles/thoughts.css">

    <title> {{ location }} - m1kadev</title>

    {{ &ogp }}

</head>

<body>