Ryozuki 7 months ago
parent
commit
78dd313520
15 changed files with 460 additions and 1 deletions
  1. 3 0
      blog/sdl2_cmake.info
  2. 86 0
      blog/sdl2_cmake.md
  3. 58 0
      index.py
  4. 2 0
      info.txt
  5. 2 0
      makecodestyles.sh
  6. 17 0
      new.py
  7. 71 0
      parse.py
  8. 0 0
      public/blog/.gitkeep
  9. 28 0
      public/blog/index.html
  10. 86 0
      public/blog/sdl2_cmake.html
  11. 69 0
      public/css/code.css
  12. 23 1
      public/css/style.css
  13. 1 0
      public/index.html
  14. BIN
      public/jaosucks.png
  15. 14 0
      remove.py

+ 3 - 0
blog/sdl2_cmake.info

@@ -0,0 +1,3 @@
+Setting Up SDL2 with CMake
+Here I explain how to setup and use SDL2 using the CMake build tool.
+2019-04-27 12:57:28.889473

+ 86 - 0
blog/sdl2_cmake.md

@@ -0,0 +1,86 @@
+# -{title}
+---
+## Installing CMake
+
+Most common distributions have cmake available on their package manager repostories:
+
+```bash
+# Debian based
+sudo apt install cmake
+
+# Arch
+pacman -S cmake
+```
+
+## Install SDL2 libraries
+
+I only know about the debian based ones, if you are on another distro you should look them up.
+
+```bash
+sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-net-dev libsdl2-ttf-dev libsdl2-gfx-dev
+```
+
+## Directory Structure
+
+Here is a common directory structure when using cmake to find packages:
+
+```
+├── cmake
+│   ├── FindSDL2.cmake
+│   ├── FindSDL2_mixer.cmake
+│   └── FindSDL2_net.cmake
+├── CMakeLists.txt
+└── src
+    └── main.cpp
+```
+
+You can find the cmake files to find SDL2 and it's components
+[here](https://github.com/aminosbh/sdl2-cmake-modules)
+
+Or you can use this simple command:
+
+```bash
+cd cmake
+wget https://raw.githubusercontent.com/aminosbh/sdl2-cmake-modules/master/FindSDL2{,_gfx,_image,_mixer,_net,_ttf}.cmake
+```
+
+## Creating the CMakeLists.txt file
+
+```cmake
+cmake_minimum_required(VERSION 3.13)
+project(MyProject)
+
+# Needed so that cmake uses our find modules.
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
+
+find_package(SDL2 REQUIRED)
+find_package(SDL2_net REQUIRED)
+find_package(SDL2_mixer REQUIRED)
+find_package(SDL2_image REQUIRED)
+find_package(SDL2_gfx REQUIRED)
+find_package(SDL2_ttf REQUIRED)
+
+
+set(SOURCE_FILES
+    src/main.cpp
+    )
+
+include_directories(src)
+
+add_executable(MyProject ${SOURCE_FILES})
+target_link_libraries(MyProject SDL2::Main SDL2::Net SDL2::Mixer SDL2::Image SDL2::TTF SDL2::GFX)
+
+```
+
+And thats it! Now you can remove the SDL2 components you don't want to use.
+
+## Building
+
+Following the standard cmake procedure:
+
+```bash
+mkdir build
+cd build
+cmake ..
+make -j${nproc}
+```

+ 58 - 0
index.py

@@ -0,0 +1,58 @@
+#!/usr/bin/env python3
+
+import os
+from datetime import datetime
+from operator import itemgetter
+
+base = """
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>Ryozuki Blog</title>
+    <meta name="description" content="All blog entries are listed here.">
+    <meta name="author" content="Ryozuki">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <link rel="stylesheet" href="/css/code.css">
+    <link rel="stylesheet" href="/css/style.css">
+    <meta name="twitter:card" content="summary" />
+    <meta name="twitter:site" content="@ShinobuWR" />
+    <meta name="twitter:creator" content="@ShinobuWR" />
+    <meta property="og:title" content="Ryozuki Blog" />
+    <meta property="og:description" content="All blog entries are listed here." />
+    <meta name='medium' content='blog'>
+</head>
+
+<body>
+<h2><span class="green">[</span> Ryozuki Blog Index <span class="green">]</span></h2>
+<ul>
+{body}
+</ul>
+
+</body>
+
+</html>
+"""
+
+if __name__ == "__main__":
+    index = []
+    for x in os.listdir("blog"):
+        name, ext = os.path.splitext(x)
+
+        if ext != ".info":
+            continue
+
+        with open(f"blog/{x}") as f:
+            title = f.readline().replace("\n", "").strip()
+            about = f.readline().replace("\n", "").strip()
+            date = f.readline().strip().replace("\n", "")
+            index.append((
+                datetime.strptime(date, '%Y-%m-%d %H:%M:%S.%f'),
+                f"<li>[<span class='green'>{date}</span>] <a href='/blog/{name}.html'>{title}</a></li>"
+                ))
+    body = ""
+    index.sort(key=itemgetter(0))
+    for x in index:
+        body += x[1] + "\n"
+
+    with open("public/blog/index.html", 'w') as f:
+        f.write(base.replace("{body}", body))

+ 2 - 0
info.txt

@@ -0,0 +1,2 @@
+Use: pygmentize -S default -f html > style.css
+to generate code highlight css

+ 2 - 0
makecodestyles.sh

@@ -0,0 +1,2 @@
+#!/usr/bin/env bash
+pygmentize -S monokai -f html > public/css/code.css

+ 17 - 0
new.py

@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+
+import datetime
+
+if __name__ == "__main__":
+    print("\033[94mBlog Template Generator v1.0 by \033[1mRyozuki\033[0m")
+    print("-------")
+    name = input("Filename: ")
+    title = input("Title: ")
+    about = input("About: ")
+    date = datetime.datetime.now()
+    
+    with open(f"blog/{name}.info", 'w') as f:
+        f.write(title + "\n" + about + "\n" + str(date) + "\n")
+
+    with open(f"blog/{name}.md", 'w') as f:
+        f.write("# -{title}\n")

+ 71 - 0
parse.py

@@ -0,0 +1,71 @@
+#!/usr/bin/env python3
+
+import os
+import mistune
+from pygments import highlight
+from pygments.lexers import get_lexer_by_name
+from pygments.formatters import html
+
+
+base = """
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>-{title} | Ryozuki Blog</title>
+    <meta name="description" content="-{about}">
+    <meta name="author" content="Ryozuki">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <link rel="stylesheet" href="/css/code.css">
+    <link rel="stylesheet" href="/css/style.css">
+    <meta name="twitter:card" content="summary" />
+    <meta name="twitter:site" content="@ShinobuWR" />
+    <meta name="twitter:creator" content="@ShinobuWR" />
+    <meta property="og:title" content="-{title} | Ryozuki Blog" />
+    <meta property="og:description" content="-{about}" />
+    <meta name='medium' content='blog'>
+</head>
+
+<body>
+-{body}
+</body>
+
+</html>
+
+"""
+
+
+class HighlightRenderer(mistune.Renderer):
+    def block_code(self, code, lang):
+        if not lang:
+            return '\n<pre><code>%s</code></pre>\n' % \
+                mistune.escape(code)
+        lexer = get_lexer_by_name(lang, stripall=True)
+        formatter = html.HtmlFormatter(linenos='inline')
+        return highlight(code, lexer, formatter)
+
+    def header(self, text, level, raw=None):
+        return '<h%d><span class="green">[</span>%s<span class="green">]</span></h%d>\n' % (level, text, level)
+
+if __name__ == "__main__":
+    renderer = HighlightRenderer()
+    markdown = mistune.Markdown(renderer=renderer)
+    
+    for x in os.listdir("blog"):
+        with open(f"blog/{x}") as f:
+            parsed = markdown(f.read())
+            name, ext = os.path.splitext(x)
+            if ext != ".md":
+                continue
+            info = open(f"blog/{name}.info", 'r')
+            title = info.readline().replace("\n", "").strip()
+            about = info.readline().replace("\n", "").strip()
+            date = info.readline().replace("\n", "").strip()
+            info.close()
+            _base = base.replace("-{title}", title)
+            _base = _base.replace("-{about}", about)
+            parsed = parsed.replace("-{title}", title)
+            parsed = parsed.replace("-{date}", date)
+            _base = _base.replace("-{body}", parsed)
+            with open(f"public/blog/{name}.html", 'w') as out:
+                out.write(_base)
+            print(f"\033[94mGenerated file: \033[92m\033[1m{name}.html\033[0m")

+ 0 - 0
public/blog/.gitkeep


+ 28 - 0
public/blog/index.html

@@ -0,0 +1,28 @@
+
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>Ryozuki Blog</title>
+    <meta name="description" content="All blog entries are listed here.">
+    <meta name="author" content="Ryozuki">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <link rel="stylesheet" href="/css/code.css">
+    <link rel="stylesheet" href="/css/style.css">
+    <meta name="twitter:card" content="summary" />
+    <meta name="twitter:site" content="@ShinobuWR" />
+    <meta name="twitter:creator" content="@ShinobuWR" />
+    <meta property="og:title" content="Ryozuki Blog" />
+    <meta property="og:description" content="All blog entries are listed here." />
+    <meta name='medium' content='blog'>
+</head>
+
+<body>
+<h2><span class="green">[</span> Ryozuki Blog Index <span class="green">]</span></h2>
+<ul>
+<li>[<span class='green'>2019-04-27 12:57:28.889473</span>] <a href='/blog/sdl2_cmake.html'>Setting Up SDL2 with CMake</a></li>
+
+</ul>
+
+</body>
+
+</html>

+ 86 - 0
public/blog/sdl2_cmake.html

@@ -0,0 +1,86 @@
+
+<html>
+<head>
+    <meta charset="UTF-8">
+    <title>Setting Up SDL2 with CMake | Ryozuki Blog</title>
+    <meta name="description" content="Here I explain how to setup and use SDL2 using the CMake build tool.">
+    <meta name="author" content="Ryozuki">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <link rel="stylesheet" href="/css/code.css">
+    <link rel="stylesheet" href="/css/style.css">
+    <meta name="twitter:card" content="summary" />
+    <meta name="twitter:site" content="@ShinobuWR" />
+    <meta name="twitter:creator" content="@ShinobuWR" />
+    <meta property="og:title" content="Setting Up SDL2 with CMake | Ryozuki Blog" />
+    <meta property="og:description" content="Here I explain how to setup and use SDL2 using the CMake build tool." />
+    <meta name='medium' content='blog'>
+</head>
+
+<body>
+<h1><span class="green">[</span>Setting Up SDL2 with CMake<span class="green">]</span></h1>
+<hr>
+<h2><span class="green">[</span>Installing CMake<span class="green">]</span></h2>
+<p>Most common distributions have cmake available on their package manager repostories:</p>
+<div class="highlight"><pre><span></span><span class="lineno">1 </span><span class="c1"># Debian based</span>
+<span class="lineno">2 </span>sudo apt install cmake
+<span class="lineno">3 </span>
+<span class="lineno">4 </span><span class="c1"># Arch</span>
+<span class="lineno">5 </span>pacman -S cmake
+</pre></div>
+<h2><span class="green">[</span>Install SDL2 libraries<span class="green">]</span></h2>
+<p>I only know about the debian based ones, if you are on another distro you should look them up.</p>
+<div class="highlight"><pre><span></span><span class="lineno">1 </span>sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-net-dev libsdl2-ttf-dev libsdl2-gfx-dev
+</pre></div>
+<h2><span class="green">[</span>Directory Structure<span class="green">]</span></h2>
+<p>Here is a common directory structure when using cmake to find packages:</p>
+
+<pre><code>├── cmake
+│   ├── FindSDL2.cmake
+│   ├── FindSDL2_mixer.cmake
+│   └── FindSDL2_net.cmake
+├── CMakeLists.txt
+└── src
+    └── main.cpp</code></pre>
+<p>You can find the cmake files to find SDL2 and it's components
+<a href="https://github.com/aminosbh/sdl2-cmake-modules">here</a></p>
+<p>Or you can use this simple command:</p>
+<div class="highlight"><pre><span></span><span class="lineno">1 </span><span class="nb">cd</span> cmake
+<span class="lineno">2 </span>wget https://raw.githubusercontent.com/aminosbh/sdl2-cmake-modules/master/FindSDL2<span class="o">{</span>,_gfx,_image,_mixer,_net,_ttf<span class="o">}</span>.cmake
+</pre></div>
+<h2><span class="green">[</span>Creating the CMakeLists.txt file<span class="green">]</span></h2>
+<div class="highlight"><pre><span></span><span class="lineno"> 1 </span><span class="nb">cmake_minimum_required</span><span class="p">(</span><span class="s">VERSION</span> <span class="s">3.13</span><span class="p">)</span>
+<span class="lineno"> 2 </span><span class="nb">project</span><span class="p">(</span><span class="s">MyProject</span><span class="p">)</span>
+<span class="lineno"> 3 </span>
+<span class="lineno"> 4 </span><span class="c"># Needed so that cmake uses our find modules.</span>
+<span class="lineno"> 5 </span><span class="nb">list</span><span class="p">(</span><span class="s">APPEND</span> <span class="s">CMAKE_MODULE_PATH</span> <span class="o">${</span><span class="nv">CMAKE_CURRENT_SOURCE_DIR</span><span class="o">}</span><span class="s">/cmake</span><span class="p">)</span>
+<span class="lineno"> 6 </span>
+<span class="lineno"> 7 </span><span class="nb">find_package</span><span class="p">(</span><span class="s">SDL2</span> <span class="s">REQUIRED</span><span class="p">)</span>
+<span class="lineno"> 8 </span><span class="nb">find_package</span><span class="p">(</span><span class="s">SDL2_net</span> <span class="s">REQUIRED</span><span class="p">)</span>
+<span class="lineno"> 9 </span><span class="nb">find_package</span><span class="p">(</span><span class="s">SDL2_mixer</span> <span class="s">REQUIRED</span><span class="p">)</span>
+<span class="lineno">10 </span><span class="nb">find_package</span><span class="p">(</span><span class="s">SDL2_image</span> <span class="s">REQUIRED</span><span class="p">)</span>
+<span class="lineno">11 </span><span class="nb">find_package</span><span class="p">(</span><span class="s">SDL2_gfx</span> <span class="s">REQUIRED</span><span class="p">)</span>
+<span class="lineno">12 </span><span class="nb">find_package</span><span class="p">(</span><span class="s">SDL2_ttf</span> <span class="s">REQUIRED</span><span class="p">)</span>
+<span class="lineno">13 </span>
+<span class="lineno">14 </span>
+<span class="lineno">15 </span><span class="nb">set</span><span class="p">(</span><span class="s">SOURCE_FILES</span>
+<span class="lineno">16 </span>    <span class="s">src/main.cpp</span>
+<span class="lineno">17 </span>    <span class="p">)</span>
+<span class="lineno">18 </span>
+<span class="lineno">19 </span><span class="nb">include_directories</span><span class="p">(</span><span class="s">src</span><span class="p">)</span>
+<span class="lineno">20 </span>
+<span class="lineno">21 </span><span class="nb">add_executable</span><span class="p">(</span><span class="s">MyProject</span> <span class="o">${</span><span class="nv">SOURCE_FILES</span><span class="o">}</span><span class="p">)</span>
+<span class="lineno">22 </span><span class="nb">target_link_libraries</span><span class="p">(</span><span class="s">MyProject</span> <span class="s">SDL2::Main</span> <span class="s">SDL2::Net</span> <span class="s">SDL2::Mixer</span> <span class="s">SDL2::Image</span> <span class="s">SDL2::TTF</span> <span class="s">SDL2::GFX</span><span class="p">)</span>
+</pre></div>
+<p>And thats it! Now you can remove the SDL2 components you don't want to use.</p>
+<h2><span class="green">[</span>Building<span class="green">]</span></h2>
+<p>Following the standard cmake procedure:</p>
+<div class="highlight"><pre><span></span><span class="lineno">1 </span>mkdir build
+<span class="lineno">2 </span><span class="nb">cd</span> build
+<span class="lineno">3 </span>cmake ..
+<span class="lineno">4 </span>make -j<span class="si">${</span><span class="nv">nproc</span><span class="si">}</span>
+</pre></div>
+
+</body>
+
+</html>
+

+ 69 - 0
public/css/code.css

@@ -0,0 +1,69 @@
+.hll { background-color: #49483e }
+.c { color: #75715e } /* Comment */
+.err { color: #960050; background-color: #1e0010 } /* Error */
+.k { color: #66d9ef } /* Keyword */
+.l { color: #ae81ff } /* Literal */
+.n { color: #f8f8f2 } /* Name */
+.o { color: #f92672 } /* Operator */
+.p { color: #f8f8f2 } /* Punctuation */
+.ch { color: #75715e } /* Comment.Hashbang */
+.cm { color: #75715e } /* Comment.Multiline */
+.cp { color: #75715e } /* Comment.Preproc */
+.cpf { color: #75715e } /* Comment.PreprocFile */
+.c1 { color: #75715e } /* Comment.Single */
+.cs { color: #75715e } /* Comment.Special */
+.gd { color: #f92672 } /* Generic.Deleted */
+.ge { font-style: italic } /* Generic.Emph */
+.gi { color: #a6e22e } /* Generic.Inserted */
+.gs { font-weight: bold } /* Generic.Strong */
+.gu { color: #75715e } /* Generic.Subheading */
+.kc { color: #66d9ef } /* Keyword.Constant */
+.kd { color: #66d9ef } /* Keyword.Declaration */
+.kn { color: #f92672 } /* Keyword.Namespace */
+.kp { color: #66d9ef } /* Keyword.Pseudo */
+.kr { color: #66d9ef } /* Keyword.Reserved */
+.kt { color: #66d9ef } /* Keyword.Type */
+.ld { color: #e6db74 } /* Literal.Date */
+.m { color: #ae81ff } /* Literal.Number */
+.s { color: #e6db74 } /* Literal.String */
+.na { color: #a6e22e } /* Name.Attribute */
+.nb { color: #f8f8f2 } /* Name.Builtin */
+.nc { color: #a6e22e } /* Name.Class */
+.no { color: #66d9ef } /* Name.Constant */
+.nd { color: #a6e22e } /* Name.Decorator */
+.ni { color: #f8f8f2 } /* Name.Entity */
+.ne { color: #a6e22e } /* Name.Exception */
+.nf { color: #a6e22e } /* Name.Function */
+.nl { color: #f8f8f2 } /* Name.Label */
+.nn { color: #f8f8f2 } /* Name.Namespace */
+.nx { color: #a6e22e } /* Name.Other */
+.py { color: #f8f8f2 } /* Name.Property */
+.nt { color: #f92672 } /* Name.Tag */
+.nv { color: #f8f8f2 } /* Name.Variable */
+.ow { color: #f92672 } /* Operator.Word */
+.w { color: #f8f8f2 } /* Text.Whitespace */
+.mb { color: #ae81ff } /* Literal.Number.Bin */
+.mf { color: #ae81ff } /* Literal.Number.Float */
+.mh { color: #ae81ff } /* Literal.Number.Hex */
+.mi { color: #ae81ff } /* Literal.Number.Integer */
+.mo { color: #ae81ff } /* Literal.Number.Oct */
+.sa { color: #e6db74 } /* Literal.String.Affix */
+.sb { color: #e6db74 } /* Literal.String.Backtick */
+.sc { color: #e6db74 } /* Literal.String.Char */
+.dl { color: #e6db74 } /* Literal.String.Delimiter */
+.sd { color: #e6db74 } /* Literal.String.Doc */
+.s2 { color: #e6db74 } /* Literal.String.Double */
+.se { color: #ae81ff } /* Literal.String.Escape */
+.sh { color: #e6db74 } /* Literal.String.Heredoc */
+.si { color: #e6db74 } /* Literal.String.Interpol */
+.sx { color: #e6db74 } /* Literal.String.Other */
+.sr { color: #e6db74 } /* Literal.String.Regex */
+.s1 { color: #e6db74 } /* Literal.String.Single */
+.ss { color: #e6db74 } /* Literal.String.Symbol */
+.bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
+.fm { color: #a6e22e } /* Name.Function.Magic */
+.vc { color: #f8f8f2 } /* Name.Variable.Class */
+.vg { color: #f8f8f2 } /* Name.Variable.Global */
+.vi { color: #f8f8f2 } /* Name.Variable.Instance */
+.vm { color: #f8f8f2 } /* Name.Variable.Magic */
+.il { color: #ae81ff } /* Literal.Number.Integer.Long */

+ 23 - 1
public/css/style.css

@@ -6,6 +6,28 @@ body {
     font-family: "Courier New", Courier, monospace;
 }
 
+.highlight pre {
+    overflow: auto;
+    overflow-y: hidden;
+    border: 1px dashed #777;
+    font-size: 120%;
+    padding: 10px;
+    font-family: monospace;
+    counter-reset: line;
+}
+
+span.lineno {
+    color: grey;
+    border-right: 1px solid;
+    margin-right: 5px;
+    -webkit-touch-callout: none;
+    -webkit-user-select: none;
+    -khtml-user-select: none;
+    -moz-user-select: none;
+    -ms-user-select: none;
+    user-select: none;
+}
+
 a {
     color: springgreen;
     font-weight: bold;
@@ -87,4 +109,4 @@ tr:nth-child(even) {
 
 .test {
     color: springgreen;
-}
+}

+ 1 - 0
public/index.html

@@ -19,6 +19,7 @@
 <h2><span class="green">[</span> Ryozuki.xyz <span class="green">]</span></h2>
 <p>This is my personal website, here I save interesting things I may find, my own thoughts or any random thing.</p>
 <p>I am a self taught programmer, I currently know C, C++, python, javascript (and nodejs), C# and java.</p>
+<p>You can read my blog <a href="/blog">here</a>.</p>
 <p>Some libraries I used:
     <a href="https://www.djangoproject.com/" target="_blank">Django</a>,
     <a href="http://flask.pocoo.org/" target="_blank">Flask</a>,

BIN
public/jaosucks.png


+ 14 - 0
remove.py

@@ -0,0 +1,14 @@
+#!/usr/bin/env python3
+
+import os
+
+def remove(name):
+    if os.path.exists(name):
+        os.remove(name)
+
+if __name__ == "__main__":
+    name = input("Blog entry name: ")
+    remove(f"blog/{name}.md")
+    remove(f"blog/{name}.info")
+    remove(f"public/blog/{name}.html")
+    print("Done!")