From a63f68504a9786fc3919791f6d2a00651a37648e Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Fri, 13 Feb 2015 12:42:42 -0800 Subject: [PATCH] Add blog --- Dockerfile | 1 + app.moon | 1 + ...etting-started-with-go-2015-01-28.markdown | 143 ++++++++++++++++++ controllers/blog.moon | 31 ++++ init/startup/00_generate_index.sh | 18 +++ util.moon | 5 + views/blog/index.moon | 5 + 7 files changed, 204 insertions(+) create mode 100644 blog/getting-started-with-go-2015-01-28.markdown create mode 100644 controllers/blog.moon create mode 100755 init/startup/00_generate_index.sh create mode 100644 util.moon create mode 100644 views/blog/index.moon diff --git a/Dockerfile b/Dockerfile index 03b5807..74aa281 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,3 +3,4 @@ FROM xena/lapis:1.7.7.2 ADD init/oleg /seed/oleg RUN mv /seed/oleg/olegdb.conf /oleg/db.conf ADD init/oleg/runit/ /etc/service +ADD init/startup/ /etc/my_init.d diff --git a/app.moon b/app.moon index 8160f6d..7c316b1 100644 --- a/app.moon +++ b/app.moon @@ -8,6 +8,7 @@ class extends lapis.Application @include "controllers.go" @include "controllers.resume" @include "controllers.index" + @include "controllers.blog" [contact: "/contact"]: => @title = "Contact" diff --git a/blog/getting-started-with-go-2015-01-28.markdown b/blog/getting-started-with-go-2015-01-28.markdown new file mode 100644 index 0000000..d357a42 --- /dev/null +++ b/blog/getting-started-with-go-2015-01-28.markdown @@ -0,0 +1,143 @@ +Getting Started with Go +======================= + +Go is an exciting language made by Google for systems programming. This article +will help you get up and running with the Go compiler tools. + +System Setup +------------ + +First you need to install the compilers. + +```console +$ sudo apt-get install golang golang-go.tools +``` + +`golang-go.tools` contains some useful tools that aren't part of the standard +Go distribution. + +Shell Setup +----------- + +Create a folder in your home directory for your Go code to live in. I use +`~/go`. + +```console +$ mkdir -p ~/go/{bin,pkg,src} +``` + +`bin` contains go binaries that are created from `go get` or `go install`. +`pkg` contains static (`.a`) compiled versions of go packages that are not go +programs. `src` contains go source code. + +After you create this, add +[this](https://github.com/Xe/dotfiles/blob/master/.zsh/go-completion.zsh) and +the following to your zsh config: + +```sh +export GOPATH=$HOME/go +export PATH=$PATH:/usr/lib/go/bin:$GOPATH/bin +``` + +This will add the go compilers to your `$PATH` as well as programs you install. + +Rehash your shell config (I use +a [`resource`](https://github.com/Xe/dotfiles/blob/master/.zsh/resource.zsh#L3) +command for this) and then run: + +```console +$ go env +GOARCH="amd64" +GOBIN="" +GOCHAR="6" +GOEXE="" +GOHOSTARCH="amd64" +GOHOSTOS="linux" +GOOS="linux" +GOPATH="/home/xena/go" +GORACE="" +GOROOT="/usr/lib/go" +GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64" +TERM="dumb" +CC="gcc" +GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread" +CXX="g++" +CGO_ENABLED="1" +``` + +This will verify that the go toolchain knows where the go compilers are as well +as where your `$GOPATH` is. + +Testing +------- + +To test the go compilers with a simple +[todo command](http://github,com/mattn/todo), run this: + +```console +$ go get github.com/mattn/todo +$ todo add foo +$ todo list +☐ 001: foo +``` + +Vim Setup +--------- + +For Vim integration, I suggest using the +[vim-go](https://github.com/fatih/vim-go) plugin. This plugin used to be part +of the standard Go distribution. + +To install: + +1. Add `Plugin 'fatih/vim-go'` to the plugins part of your vimrc. +2. Run these commands: + +```console +$ vim +PluginInstall +qall +$ vim +GoInstallBinaries +qall +``` + +This will install the go oracle and the go autocompletion daemon gocode as well +as some other useful tools that will integrate seamlessly into vim. This will +also run `gofmt` on save to style your code to the standard way to write Go +code. + +Resources +--------- + +[Effective Go](https://golang.org/doc/effective_go.html) and the +[language spec](https://golang.org/ref/spec) provide a nice overview of the +syntax. + +The Go [blog](http://blog.golang.org) contains a lot of detailed articles +covering advanced and simple Go topics. +[This page](https://golang.org/doc/#articles) has a list of past articles that +you may find useful. + +The Go standard library is a fantastic collection of Go code for solving many +problems. In some cases you can even write entire programs using only the +standard library. This includes things like web application support, tarfile +support, sql drivers, support for most kinds of commonly used crypto, command +line flag parsing, html templating, and regular expressions. A full list of +the standard library packages can be found [here](http://godoc.org/-/go). + +Variable type declarations will look backwards. It takes a bit to get used to +but makes a lot of sense once you realize it reads better left to right. + +For a nice primer on building web apps with Go, codegangsta is writing a book +on the common first steps, starting from the standard library and working up. +You can find his work in progress book +[here](http://codegangsta.gitbooks.io/building-web-apps-with-go/). + +Go has support for unit testing baked into the core language tools. You can +find information about writing unit tests [here](http://golang.org/pkg/testing/). + +When creating a new go project, please resist the urge to make the folder in your +normal code folder. Drink the `$GOPATH` koolaid. Yes it's annoying, yes it's the +language forcing you to use its standard. Just try it. It's an amazingly useful +thing once you get used to it. + +Learn to love godoc. Godoc lets you document code like +[this](https://gist.github.com/Xe/b973e30d81280899955d). This also includes an +example of the builtin unit testing support. diff --git a/controllers/blog.moon b/controllers/blog.moon new file mode 100644 index 0000000..a955e68 --- /dev/null +++ b/controllers/blog.moon @@ -0,0 +1,31 @@ +discount = require "discount" +lapis = require "lapis" +file = require "pl.file" +http = require "lapis.nginx.http" +oleg = require "lib/oleg" +util = require "lapis.util" +dir = require "pl.dir" + +import render_html from require "lapis.html" +split = require "util" + +class Blog extends lapis.Application + ["blog.index": "/blog"]: => + @doc = oleg.cache "caches", "blog-index", -> + local data + with io.open "static/markdown/blog.html", "r" + data = \read "*a" + data + + render: true + + ["blog.post": "/blog/:name"]: => + @name = util.slugify @params.name + @doc = oleg.cache "blogposts", @name, -> + local data + with io.open "blog/#{@name}.markdown", "r" + data = \read "*a" + + discount data, "toc", "nopants", "autolink" + + render: true diff --git a/init/startup/00_generate_index.sh b/init/startup/00_generate_index.sh new file mode 100755 index 0000000..d38caba --- /dev/null +++ b/init/startup/00_generate_index.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -e + +cd /app/src/blog + +IFS=' +' + +for file in * +do + title=$(head -n1 $file) + line=$(head -n4 $file | tail -n1) + linkname=$(echo $file | awk -F "." '{print $1}') + + echo '

'"$title"'

'"$line"'...

Read More
' >> /app/src/static/markdown/blog.html + echo "generated info for $file" +done diff --git a/util.moon b/util.moon new file mode 100644 index 0000000..99a40ab --- /dev/null +++ b/util.moon @@ -0,0 +1,5 @@ +split = (s, delimiter) -> + result = {} + for match in (s..delimiter)\gmatch "(.-)"..delimiter + table.insert result, match + result diff --git a/views/blog/index.moon b/views/blog/index.moon new file mode 100644 index 0000000..9e8d375 --- /dev/null +++ b/views/blog/index.moon @@ -0,0 +1,5 @@ +import Widget from require "lapis.html" + +class UserInfo extends Widget + content: => + raw @doc