Skip to content

Commit

Permalink
Add proper Drone config, README and fix issues (ineff/errcheck)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Lhussiez committed Aug 22, 2019
1 parent 300fb9e commit 1660561
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 33 deletions.
74 changes: 57 additions & 17 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,59 @@
workspace:
base: /go
path: src/github.com/Depado/smallblog/
---
kind: pipeline
name: default

pipeline:
prerequisites:
image: golang:1.10
commands:
- go get -u github.com/golang/dep/cmd/dep
- dep ensure
steps:
- name: fetch
image: docker:git
commands:
- git fetch --tags

test:
image: golang:1.10
commands:
- bash coverage.sh

codecov:
image: robertstettner/drone-codecov
secrets: [ codecov_token ]
- name: test
image: golang:latest
volumes:
- name: deps
path: /go
commands:
- go test -race -coverprofile=coverage.txt -covermode=atomic
environment:
GO111MODULE: "on"

- name: linter
image: golang:latest
volumes:
- name: deps
path: /go
commands:
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.17.1
- ./bin/golangci-lint run
environment:
GO111MODULE: "on"

- name: coverage
image: plugins/codecov
settings:
token:
from_secret: codecov_token
files:
- coverage.txt

- name: telegram
image: appleboy/drone-telegram
settings:
to: 790376882
format: markdown
token:
from_secret: telegram_token
message: >
*{{repo.name}}*
[Build {{build.number}}]({{build.link}}) by {{commit.author}} {{#success build.status}}succeeded{{else}}failed{{/success}} in {{buildtime build.started}}
`{{truncate commit.sha 8}}`: "{{commit.message}}"
when:
status:
- success
- failure

volumes:
- name: deps
host:
path: /var/lib/cache/godeps/
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Smallblog

![Go Version](https://img.shields.io/badge/go-1.9-brightgreen.svg)
![Go Version](https://img.shields.io/badge/go-1.10-brightgreen.svg)
![Go Version](https://img.shields.io/badge/go-latest-brightgreen)
[![Go Report Card](https://goreportcard.com/badge/github.com/Depado/smallblog)](https://goreportcard.com/report/github.com/Depado/smallblog)
[![Build Status](https://drone.depado.eu/api/badges/Depado/smallblog/status.svg)](https://drone.depado.eu/Depado/smallblog)
[![Build Status](https://drone.depa.do/api/badges/Depado/smallblog/status.svg)](https://drone.depa.do/Depado/smallblog)
[![codecov](https://codecov.io/gh/Depado/smallblog/branch/master/graph/badge.svg)](https://codecov.io/gh/Depado/smallblog)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Depado/smallblog/blob/master/LICENSE)

Expand All @@ -26,19 +25,20 @@ that's not as fun.

## Features

- Filesystem monitoring : Drop a new file or modify a file, bam, your blog is
updated
- Filesystem monitoring: Create, modify or delete a file and your blog is
updated
- Automatic syntax highlighting using [bfchroma](https://github.com/Depado/bfchroma)
(which uses [chroma](https://github.com/alecthomas/chroma) under the hood)
(which uses [chroma](https://github.com/alecthomas/chroma) under the hood)
- Supports [admonitions](https://python-markdown.github.io/extensions/admonition/)
using [bfadmonition](https://github.com/Depado/bfadmonition)
- No CGO dependencies
- Tag system
- Simple and customizable template and CSS for easy reading
- Comments using [gitalk](https://github.com/gitalk/gitalk)
- Supports global assets for all your articles
- Can generate a static site :
- Can generate a static site:
- Tags won't work
- Raw markdown won't work
- Can't test without a proper web server like Caddy or Nginx

## Tutorial

Expand Down Expand Up @@ -213,7 +213,7 @@ post's title if it is omitted.

## Example Article

`pages/example-article`
`pages/example-article.md`

```
title: "Example article !"
Expand Down
10 changes: 9 additions & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ var generate = &cobra.Command{
logrus.WithError(err).Fatal("Couldn't parse directory")
}
t, err := template.ParseGlob("templates/*.tmpl")
if err != nil {
logrus.WithError(err).Fatal("Unable to parse templates")
}
for _, v := range models.MPages {
var fd *os.File
v.Slug = v.Slug + ".html"
if fd, err = os.Create(filepath.Join(pages, v.Slug)); err != nil {
logrus.WithError(err).Fatal("Couldn't create file")
}
t.ExecuteTemplate(fd, "post.tmpl", gin.H{"post": v, "gitalk": models.GetGitalk(), "local": true})
if err = t.ExecuteTemplate(
fd, "post.tmpl",
gin.H{"post": v, "gitalk": models.GetGitalk(), "local": true},
); err != nil {
logrus.WithError(err).Fatal("Unable to execute template")
}
}
var fd *os.File
if fd, err = os.Create(filepath.Join(output, "index.html")); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ func init() {
newCmd.Flags().String("author.github", "", "github username of the author (overrides global conf)")
newCmd.Flags().String("author.site", "", "website of the author (overrides global conf)")
newCmd.Flags().String("author.avatar", "", "URL to the author's avatar (overrides global conf)")
viper.BindPFlags(newCmd.Flags())
viper.BindPFlags(newCmd.Flags()) // nolint: errcheck
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func init() {
rootCmd.PersistentFlags().Bool("blog.share", false, "add a Twitter share button on articles")

// Flag binding
viper.BindPFlags(rootCmd.PersistentFlags())
viper.BindPFlags(rootCmd.PersistentFlags()) // nolint: errcheck
}

func initialize() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ func init() {
serve.Flags().String("gitalk.repo", "", "repository where the comments will be stored")
serve.Flags().String("gitalk.owner", "", "repository owner")
serve.Flags().StringArray("gitalk.admins", []string{}, "gitalk admins")
viper.BindPFlags(serve.Flags())
viper.BindPFlags(serve.Flags()) // nolint: errcheck
}
8 changes: 6 additions & 2 deletions filesystem/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"

"github.com/rjeczalik/notify"
"github.com/sirupsen/logrus"

"github.com/Depado/smallblog/models"
)
Expand All @@ -30,11 +31,14 @@ func Watch(dir string) {
case notify.Write, notify.InMovedTo:
if p, ok := m[filepath.Base(ei.Path())]; ok {
// Existing file, needs to be parsed.
p.UpdateFromFile(ei.Path())
if err = p.UpdateFromFile(ei.Path()); err != nil {
logrus.WithError(err).WithField("file", ei.Path()).Error("Unable to update post")
}
} else {
// New file. Needs to be parsed and inserted.
p := new(models.Page)
var p *models.Page
if p, err = models.NewPageFromFile(ei.Path()); err != nil {
logrus.WithError(err).WithField("file", ei.Path()).Error("Unable to update post")
continue
}
m[filepath.Base(ei.Path())] = p
Expand Down
6 changes: 5 additions & 1 deletion views/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sort"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"

"github.com/Depado/smallblog/models"
Expand Down Expand Up @@ -69,7 +70,10 @@ func Post(c *gin.Context) {
func RawPost(c *gin.Context) {
slug := c.Param("slug")
if val, ok := models.MPages[slug]; ok {
c.Writer.Write([]byte(val.Raw))
if _, err := c.Writer.Write([]byte(val.Raw)); err != nil {
logrus.WithError(err).Error("Unable to write raw markdown")
c.String(http.StatusInternalServerError, "500 internal server error")
}
} else {
c.String(http.StatusNotFound, "404 not found")
}
Expand Down

0 comments on commit 1660561

Please sign in to comment.