1
0
mirror of https://github.com/danog/gojekyll.git synced 2025-01-22 17:51:25 +01:00
This commit is contained in:
Oliver Steele 2017-07-08 21:41:35 -04:00
parent 90b1422567
commit e8fdcfbe5a
3 changed files with 48 additions and 35 deletions

View File

@ -48,10 +48,11 @@ Missing features:
- Excerpts
- Pagination
- Math
- Plugins (except `jekyll-avatar` and `jekyll-gist`)
- `site-static_files`, `site.html_files`, and `site.tags`
- CSV and JSON data files
- Plugins (except `jekyll-avatar`, `jekyll-gist`, and `jekyll-redirect-from`, which are simulated)
- `site-static_files`, `site.html_files`, and `site.tags`
- Jekyll liquid filters: `group_by_exp`, `cgi_escape`, `uri_escape`, `scssify`, and `smartify`
- Windows compatibility
For more detailed status:
@ -63,6 +64,8 @@ For more detailed status:
These will probably not change.
- `uniq` doesn't work the same way as in Jekyll / Shopify Liquid. See the [Go Liquid differences](https://github.com/osteele/liquid#differences) for more on this.
- Real Jekyll provides an (undocumented) `jekyll.version` variable to templates. Copying this didn't seem right.
- `serve` generates pages on the fly; it doesn't write to the file system.
- Files are cached to `/tmp/gojekyll-${USER}`, not `./.sass-cache`
- Server live reload is always on.
@ -171,14 +174,16 @@ Gojekyll uses these libraries:
| [gopkg.in/alecthomas/kingpin.v2](https://github.com/alecthomas/kingpin) | Alec Thomas | command line and flag parser | MIT |
| [gopkg.in/yaml.v2](https://github.com/go-yaml/yaml) | Canonical | YAML support | Apache License 2.0 |
In addition to being totally and obviously inspired by Jekyll, Jekyll's *documentation* was solid and indispensible. Many of the filter test cases are taken directly from the Jekyll documentation, and during development the [Jekyll docs](https://jekyllrb.com/docs/home/) were always open in at least one tab.
The text for `gojekyll help` was taken from the output of `jekyll help`, and is used under the terms of the MIT license.
The text for `gojekyll help` was taken from the output of `jekyll help`.
Many of the filter test cases are taken directly from the Jekyll documentation, and are used under the terms of the MIT license.
The template for page redirections was adapted from the template in <https://github.com/jekyll/jekyll-redirect-from>.
The template for `jekyll-redirect-from` page redirects was adapted from the template in <https://github.com/jekyll/jekyll-redirect-from>, and is used under the terms of the MIT license.
The gopher image in the `testdata` directory is from [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Gophercolor.jpg). It is used under the [Creative Commons Attribution-Share Alike 3.0 Unported license](https://creativecommons.org/licenses/by-sa/3.0/deed.en).
In addition to being totally and obviously inspired by Jekyll and its plugins, Jekyll's *documentation* was solid and indispensible. During development the [Jekyll docs](https://jekyllrb.com/docs/home/) were always open in at least one tab.
## Related
[Hugo](https://gohugo.io) is *the* pre-eminent Go static site generator. It isn't Jekyll-compatible (-), but it's extraordinarily polished, performant, and productized (+++).

View File

@ -8,6 +8,8 @@ package plugins
import (
"fmt"
"github.com/osteele/gojekyll/config"
"github.com/osteele/gojekyll/pages"
"github.com/osteele/liquid"
"github.com/osteele/liquid/render"
)
@ -18,6 +20,32 @@ type PluginContext interface {
TemplateEngine() liquid.Engine
}
// Site is the site interface that is available to a plugin.
type Site interface {
AddDocument(pages.Document, bool)
Config() *config.Config
Pages() []pages.Page
}
// Plugin describes the hooks that a plugin can override.
type Plugin interface {
PostRead(site Site) error
}
type plugin struct{}
func (p plugin) PostRead(site Site) error { return nil }
// Find looks up a plugin by name
func Find(name string) (Plugin, bool) {
switch name {
case "jekyll-redirect-from":
return jekyllFeedPlugin{}, true
default:
return nil, false
}
}
// Install installs a plugin from the plugin directory.
func Install(name string, ctx PluginContext) bool {
p, found := directory[name]
@ -79,6 +107,6 @@ func (h pluginHelper) makeUnimplementedTag() liquid.Renderer {
fmt.Printf("The %q tag in the %q plugin has not been implemented.\n", ctx.TagName(), h.name)
warned = true
}
return "", nil
return fmt.Sprintf(`<!-- unimplemented tag: %q -->`, ctx.TagName()), nil
}
}

View File

@ -3,35 +3,14 @@ package plugins
import (
"bytes"
"fmt"
"html/template"
"io"
"strings"
"text/template"
"github.com/osteele/gojekyll/pages"
)
type Site interface {
AddDocument(pages.Document, bool)
Pages() []pages.Page
}
type Plugin interface {
PostRead(site Site) error
}
type plugin struct{}
func (p plugin) PostRead(site Site) error { return nil }
type jekyllFeedPlugin struct{}
func Find(name string) (Plugin, bool) {
switch name {
case "jekyll-redirect-from":
return jekyllFeedPlugin{}, true
default:
return nil, false
}
}
type jekyllFeedPlugin struct{ plugin }
var redirectTemplate *template.Template
@ -78,7 +57,9 @@ func (p jekyllFeedPlugin) PostRead(site Site) error {
if ok {
switch rd := rd.(type) {
case string:
var p = redirector{From: rd, To: p.Permalink()}
siteurl := site.Config().AbsoluteURL
baseurl := site.Config().BaseURL
var p = redirector{From: rd, To: strings.Join([]string{siteurl, baseurl, p.Permalink()}, "")}
redirections = append(redirections, &p)
default:
fmt.Printf("unimplemented redirect_from type: %T\n", rd)
@ -102,15 +83,14 @@ func (p jekyllFeedPlugin) PostRead(site Site) error {
}
// Adapted from https://github.com/jekyll/jekyll-redirect-from
var redirectFromText = `
<!DOCTYPE html>
var redirectFromText = `<!DOCTYPE html>
<html lang="en-US">
<meta charset="utf-8">
<title>Redirecting&hellip;</title>
<title>Redirecting</title>
<link rel="canonical" href="{{ .To }}">
<meta http-equiv="refresh" content="0; url={{ .To }}">
<meta name="robots" content="noindex">
<h1>Redirecting&hellip;</h1>
<h1>Redirecting</h1>
<a href="{{ .To }}">Click here if you are not redirected.</a>
<script>location="{{ .To }}"</script>
</html>`