gosora/files.go
Azareal bbbd0c381f Added the Cosmo and Cosmo Conflux themes. Freshly ported over from one of my other projects.
The porting is still underway, part of it relies on functionality which hasn't be implemented in Gosora yet like sidebars and alerts.

Restructured the BBCode parser plugin.
Added the [code] tag to the BBCode parser. Disabled by default for now.
Added a benchmark for comparing performance between when [code] is enabled and when it isn't.
Tweaked the templates to make them more flexible, thus allowing a wider variety of themes.
Images of the themes can now be found in the Theme Manager.
There's an emoji on each theme row to show which themes are mobile friendly and which aren't.
Fixed editing and deleting posts on Tempra Conflux.
Moved a large portion of the inline CSS in the topic_alt template into the stylesheets.
2017-01-07 06:31:04 +00:00

79 lines
1.4 KiB
Go

package main
import "log"
import "strings"
import "mime"
import "errors"
import "os"
import "io"
import "io/ioutil"
import "path/filepath"
import "net/http"
type SFile struct
{
Data []byte
Pos int64
Length int64
Mimetype string
Info os.FileInfo
FormattedModTime string
}
func (r SFile) Read(b []byte) (n int, err error) {
n = 0
if r.Pos > r.Length {
return n, io.EOF
}
size := cap(b)
if size > 0 {
for n < size {
b[n] = r.Data[r.Pos]
n++
if r.Pos == r.Length {
break
}
r.Pos++
}
}
return n, nil
}
func (r SFile) Seek(offset int64, whence int) (int64, error) {
if offset < 0 {
return 0, errors.New("negative position")
}
switch whence {
case 0:
r.Pos = offset
case 1:
r.Pos += offset
case 2:
r.Pos = r.Length + offset
default:
return 0, errors.New("invalid whence")
}
return r.Pos, nil
}
func add_static_file(path string, prefix string) error {
data, err := ioutil.ReadFile(path)
if err != nil {
return err
}
fi, err := os.Open(path)
if err != nil {
return err
}
f, err := fi.Stat()
if err != nil {
return err
}
log.Print("Adding the '" + path + "' static file")
path = strings.TrimPrefix(path, prefix)
log.Print("Added the '" + path + "' static file")
static_files["/static" + path] = SFile{data,0,int64(len(data)),mime.TypeByExtension(filepath.Ext(prefix + path)),f,f.ModTime().UTC().Format(http.TimeFormat)}
return nil
}