diff --git a/public/css/css.css b/public/css/css.css index a05d6af..5a2d4f0 100644 --- a/public/css/css.css +++ b/public/css/css.css @@ -1,4 +1,4 @@ -@import url(https://fonts.bunny.net/css?family=chivo-mono:500); +@import url(https://fonts.bunny.net/css?family=albert-sans:400,800); @import url(/css/colours.css); code { @@ -8,6 +8,34 @@ code { border-radius: var(--radius); } +h1 { + letter-spacing: -4%; +} + +h2, +h3 { + letter-spacing: -3%; + margin: calc(2*var(--margin)) 0 +} + +h1,h2,h3 { + margin-bottom:0px; +} + +.header h1 { + margin-bottom: 0.5em; +} + +ul, +ol { + padding-left: calc(4*var(--margin)); +} + +li::marker { + color: var(--link); +} + + ul.posts>li { margin-top: var(--margin); } @@ -23,7 +51,7 @@ pre.codeblock { html { color: var(--text); background-color: var(--background); - font-family: 'Chivo Mono', monospace; + font-family: 'Albert Sans', sans-serif; } body { @@ -33,9 +61,15 @@ body { a { color: var(--link); + transition: 0.1s ease-in-out; + text-decoration: none; } a:visited { + color: var(--link); +} + +a:hover { color: var(--link-visited); } @@ -49,7 +83,7 @@ body { align-items: center; justify-content: center; - line-height: 1.5; + line-height: 1.3; } #content { diff --git a/public/index.html b/public/index.html index 3ec0d87..944601a 100644 --- a/public/index.html +++ b/public/index.html @@ -2,6 +2,7 @@ + @@ -37,15 +38,13 @@ Footer
@@ -61,10 +60,10 @@ let posts = (await response.text()).split("\n"); let p = document.querySelector("#content>.content.posts>h2"); - p.innerText = "Recent posts"; + p.innerHTML = "Recent posts"; let elem = document.querySelector("#content>.content.posts>ul"); - elem.innerHTML = posts.slice(0,3).map(x => `
  • ${x}
  • `).join("\n"); + elem.innerHTML = posts.slice(0, 3).map(x => `
  • ${x}
  • `).join("\n"); elem.style.maxWidth = "40ch"; elem.classList.add("posts"); })() diff --git a/public/js/code_highlighter.js b/public/js/code_highlighter.js index d883e61..f04ab02 100644 --- a/public/js/code_highlighter.js +++ b/public/js/code_highlighter.js @@ -23,6 +23,16 @@ const match = (m) => (peek, take) => { take(m.length); return true; } +const match_identifier = (m) => (peek, take) => { + if (match(m)(peek, take)) { + if (peek(0).match(/[0-9a-z]/)) { + take(-m.length); + return false + } + return true; + } + return false; +} const take_until = (p) => (peek, take) => { let b = ""; while (!p()) { @@ -33,7 +43,7 @@ const take_until = (p) => (peek, take) => { } const simpleHighlight = (c) => (keyword) => (peek, take) => { - if (match(keyword)(peek, take)) + if (match_identifier(keyword)(peek, take)) return `${keyword}`; } @@ -60,7 +70,7 @@ const multiline_comment = (prefix, suffix) => (peek, take) => { const string = (c) => (peek, take) => { if (match(c)(peek, take)) { let b = c; - b += take_until(() => match(c)(peek,take))(peek, take); + b += take_until(() => match(c)(peek, take))(peek, take); b += c; return `${b}` } diff --git a/public/js/md2html.js b/public/js/md2html.js index aa98e10..a925dcf 100644 --- a/public/js/md2html.js +++ b/public/js/md2html.js @@ -62,13 +62,23 @@ const md2tokens = (markdown, newline) => { case '\\': i++; - if (peek(0) == 't' && peek(1) == 'o' && peek(2) == 'c') { - advance(); - advance(); - advance(); + const match_word = (word) => { + for (let j = 0; j < word.length; j++) { + if (peek(j) != word[j]) + return false; + } + i += word.length; + return true; + }; + + if (match_word("toc")) { tokens.push({ type: "toc" }); break; } + if (match_word("title")) { + tokens.push({ type: "title" }); + break; + } current_string += markdown[i]; break; @@ -131,8 +141,7 @@ const md2tokens = (markdown, newline) => { } finish(); - advance(); - advance(); + i += 2; let alt_text = capture_until("]"); advance(); if (!match("(")) { @@ -164,10 +173,7 @@ const md2tokens = (markdown, newline) => { } if (peek(0) == "-" && peek(1) == "-" && peek(2) == "-" && peek(3) == "\n") { - advance(); - advance(); - advance(); - + i += 3; tokens.push({ type: "hline" }); break; } @@ -191,6 +197,15 @@ const md2tokens = (markdown, newline) => { break; case '\n': + if ((peek(-1) != " " || peek(-2) != " ") && peek(-1) != "\n") { + current_string += " "; + tokens.push({ type: "span", content: current_string }); + current_string = ""; + newline = true; + + break; + } + if (newline_count > 2) break; @@ -198,6 +213,8 @@ const md2tokens = (markdown, newline) => { newline_count++; finish(); tokens.push({ type: "newline" }) + if (newline_count == 1 && peek(-1) == "\n") + tokens.push({ type: "newline" }) break; case '[': @@ -261,40 +278,20 @@ const highlight_code = (language, code) => { return highlight(map, code); } -const tokens2html = (tokens) => { +const tokens2html = (tokens, title) => { let output = ""; for (let token of tokens) { switch (token.type) { case "toc": - let htok = tokens.filter(x => x.type == "header"); - console.log(htok); - const createList = (tokens, depth = 2) => { - let list = ''; - let listItems = ''; - - - while (tokens.length > 0 && tokens[0].level <= depth) { - const token = tokens.shift(); - listItems += `
  • ${token.content}
  • `; - - if (tokens.length > 0 && tokens[0].level > token.depth) { - listItems += createList(tokens, token.depth + 1); - } - } - - if (listItems) { - list = `
      ${listItems}
    `; - } - - return list; - }; - - output += createList(htok); + output += "TABLE LE CONTENTOS" + break; + case "title": + output += `

    ${title}

    ` break; case "span": output += `${token.content}`; - break + break; case "bold": output += `${token.content}` break; @@ -305,7 +302,7 @@ const tokens2html = (tokens) => { output += `${token.content}` break; case "header": - output += `${token.content}` + output += `${token.content}` if (token.level == 2) output += "
    "; break; case "hline": diff --git a/public/posts/openbirch/openbirch.png b/public/posts/My language is 700x slower than python/openbirch.png similarity index 100% rename from public/posts/openbirch/openbirch.png rename to public/posts/My language is 700x slower than python/openbirch.png diff --git a/public/posts/How I made a programming language 700x slower than python.md b/public/posts/My language is 700x slower than python/post.md similarity index 100% rename from public/posts/How I made a programming language 700x slower than python.md rename to public/posts/My language is 700x slower than python/post.md diff --git a/public/posts/My language is 700x slower than python/thumbnail.png b/public/posts/My language is 700x slower than python/thumbnail.png new file mode 100644 index 0000000..27833da Binary files /dev/null and b/public/posts/My language is 700x slower than python/thumbnail.png differ diff --git a/public/posts/minecraft-proxy/hibernating.png b/public/posts/Putting hungry minecraft servers to sleep/hibernating.png similarity index 100% rename from public/posts/minecraft-proxy/hibernating.png rename to public/posts/Putting hungry minecraft servers to sleep/hibernating.png diff --git a/public/posts/Putting hungry minecraft servers to sleep.md b/public/posts/Putting hungry minecraft servers to sleep/post.md similarity index 66% rename from public/posts/Putting hungry minecraft servers to sleep.md rename to public/posts/Putting hungry minecraft servers to sleep/post.md index 894bd7b..c437ea3 100644 --- a/public/posts/Putting hungry minecraft servers to sleep.md +++ b/public/posts/Putting hungry minecraft servers to sleep/post.md @@ -2,32 +2,49 @@ Minecraft Rust Async Networking Proxy CRIU # Minecraft servers are HUNGRY -They hunger for your ram and your cpu. This makes it either expensive or laggy to try and host multiple servers at once. -This was something I encountered when my friend built a homeserver out of spare computer parts that was barely powerful enough to run a minecraft server. -The problem was that soon multiple people wanted a minecraft server hosted by him (which included us wanting to play modded minecraft). +They hunger for your ram and your cpu. This makes it either expensive or +laggy to try and host multiple servers at once. -It was a hassle to ssh into the server and start and stop the various servers depending on who wanted to play, -especially since a lot of people only played very rarily. +This was something I encountered when my friend built a homeserver out of +spare computer parts that was barely powerful enough to run a minecraft +server. -I remembered that I'd seen [a project](https://github.com/gekware/minecraft-server-hibernation) that claimed to be able to hibernate a minecraft server if nobody was playing on it. -The only issue was that it worked for a single server, and did so by starting and stopping the server process. +The problem was that soon multiple people wanted a minecraft server +hosted by him (which included us wanting to play modded minecraft). -This meant that if we wanted to join a modded server the hundreds of mods could make us wait for several minutes before we could play. +It was a hassle to ssh into the server and start and stop the various +servers depending on who wanted to play, especially since a lot of people +only played very rarily. -Another issue was the fact that it could only host a single server. This meant that we would have to run multiple intances of the watcher, -and that each server would be assigned to an arbitrary port that would be needed when connecting. +I remembered that I'd seen +[a project](https://github.com/gekware/minecraft-server-hibernation) +that claimed to be able to hibernate a minecraft server if nobody was +playing on it. The only issue was that it worked for a single server, and +did so by starting and stopping the server process. + +This meant that if we wanted to join a modded server the hundreds of mods +could make us wait for several minutes before we could play. + +Another issue was the fact that it could only host a single server. This +meant that we would have to run multiple intances of the watcher, and that +each server would be assigned to an arbitrary port that would be needed +when connecting. # Building a reverse proxy for minecraft -Since my friends server was accessible through a domain we thought it would be cool if instead of supplying a port -you could connect to a subdomain and be sent to a specific server. +Since my friends server was accessible through a domain we thought it +would be cool if instead of supplying a port you could connect to a +subdomain and be sent to a specific server. -The simplest way to do this would be to create a dhcp record for each subdomain to point to a server, -but that would be slow and tedious to set up for every server. +The simplest way to do this would be to create a dhcp record for each +subdomain to point to a server, but that would be slow and tedious to set +up for every server. -We then tried nginx, as it seemingly could magically redirect traffic to an internal port based on the subdomain. -I quickly found out that this did *not* work for minecraft servers (who would have guessed), but after doing some research -I decided on creating my own reverse proxy that spoke the minecraft protocol instead of HTTP. +We then tried nginx, as it seemingly could magically redirect traffic to +an internal port based on the subdomain. I quickly found out that this did +*not* work for minecraft servers (who would have guessed), but after doing +some research I decided on creating my own reverse proxy that spoke the +minecraft protocol instead of HTTP. # The Minecraft protocol diff --git a/public/posts/minecraft-proxy/starting.png b/public/posts/Putting hungry minecraft servers to sleep/starting.png similarity index 100% rename from public/posts/minecraft-proxy/starting.png rename to public/posts/Putting hungry minecraft servers to sleep/starting.png diff --git a/public/posts/Putting hungry minecraft servers to sleep/thumbnail.png b/public/posts/Putting hungry minecraft servers to sleep/thumbnail.png new file mode 100644 index 0000000..32593ab Binary files /dev/null and b/public/posts/Putting hungry minecraft servers to sleep/thumbnail.png differ diff --git a/public/posts/index.html b/public/posts/index.html index 808844c..279e98b 100644 --- a/public/posts/index.html +++ b/public/posts/index.html @@ -2,6 +2,7 @@ +