mirror of
https://github.com/danog/gojekyll.git
synced 2024-11-30 10:08:58 +01:00
Implement post_url
This commit is contained in:
parent
14bbe9a8f9
commit
a203a47455
13
README.md
13
README.md
@ -13,6 +13,7 @@ Missing features:
|
||||
- The [Go Liquid template engine](https://github.com/osteele/gojekyll) is also missing some tags and filters.
|
||||
- Data files must be YAML; CSV and JSON are not supported.
|
||||
- `{% highlight %}` uses Pygments. There's no way to tell it to use Rouge.
|
||||
- `<div markdown=1>` doesn't work. I think this is a limitation of the *blackfriday* Markdown processor.
|
||||
- Parse errors aren't reported very nicely.
|
||||
|
||||
Other differences from Jekyll:
|
||||
@ -45,8 +46,8 @@ gojekyll help build
|
||||
- [ ] Posts
|
||||
- [x] Categories
|
||||
- [ ] Tags
|
||||
- [ ] Drafts
|
||||
- [ ] Future
|
||||
- [x] Drafts
|
||||
- [x] Future
|
||||
- [x] Related
|
||||
- [x] Static Files
|
||||
- [x] Variables
|
||||
@ -58,7 +59,6 @@ gojekyll help build
|
||||
- [ ] Assets
|
||||
- [ ] Coffeescript
|
||||
- [x] Sass/SCSS
|
||||
- [ ] Sass cache
|
||||
- [ ] Customization
|
||||
- [x] Templates
|
||||
- [ ] Jekyll filters
|
||||
@ -68,13 +68,12 @@ gojekyll help build
|
||||
- [x] `include`
|
||||
- [ ] `include_relative`
|
||||
- [x] `link`
|
||||
- [ ] `post_url`
|
||||
- [x] `post_url`
|
||||
- [ ] `gist`
|
||||
- [ ] `highlight`
|
||||
- [ ] `markdown=1`
|
||||
- [x] `highlight`
|
||||
- [x] Includes
|
||||
- [x] `include` parameters
|
||||
- [ ] `include` variables (e.g. `{% include {{ expr }} %}`)
|
||||
- [x] `include` variables (e.g. `{% include {{ expr }} %}`)
|
||||
- [x] Permalinks
|
||||
- [ ] Pagination
|
||||
- [ ] Plugins
|
||||
|
@ -144,7 +144,7 @@ func pageFromPathOrRoute(s *sites.Site, path string) (pages.Document, error) {
|
||||
}
|
||||
return page, nil
|
||||
default:
|
||||
page, found := s.RelPathPage(path)
|
||||
page, found := s.FilePathPage(path)
|
||||
if !found {
|
||||
return nil, helpers.NewPathError("render", path, "no such file")
|
||||
}
|
||||
|
@ -18,10 +18,19 @@ func (c *Config) IsSassPath(name string) bool {
|
||||
return strings.HasSuffix(name, ".sass") || strings.HasSuffix(name, ".scss")
|
||||
}
|
||||
|
||||
// MarkdownExtensions returns a set of markdown extensions, without the initial dots.
|
||||
// markdownExtensions returns a set of markdown extensions, without the initial dots.
|
||||
func (c *Config) markdownExtensions() map[string]bool {
|
||||
extns := strings.SplitN(c.MarkdownExt, `,`, -1)
|
||||
return helpers.StringArrayToMap(extns)
|
||||
exts := strings.SplitN(c.MarkdownExt, `,`, -1)
|
||||
return helpers.StringArrayToMap(exts)
|
||||
}
|
||||
|
||||
// MarkdownExtensions returns a list of markdown extensions, with dotsa.
|
||||
func (c *Config) MarkdownExtensions() []string {
|
||||
exts := strings.SplitN(c.MarkdownExt, `,`, -1)
|
||||
for i, k :=range exts {
|
||||
exts[i] = "." + k
|
||||
}
|
||||
return exts
|
||||
}
|
||||
|
||||
// OutputExt returns the pathname's output extension. This is generally the pathname extension;
|
||||
|
@ -43,7 +43,7 @@ func (s *Server) watchFiles() error {
|
||||
log.Println("error:", err)
|
||||
continue
|
||||
}
|
||||
url, found := site.RelativeFilenameToURL(relpath)
|
||||
url, found := site.FilenameURLPath(relpath)
|
||||
if !found {
|
||||
// TODO don't warn re config and excluded files
|
||||
log.Println("error:", filename, "does not match a site URL")
|
||||
|
@ -93,8 +93,8 @@ func (s *Site) KeepFile(path string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// RelPathPage returns a Page, give a file path relative to site source directory.
|
||||
func (s *Site) RelPathPage(relpath string) (pages.Document, bool) {
|
||||
// FilePathPage returns a Page, give a file path relative to site source directory.
|
||||
func (s *Site) FilePathPage(relpath string) (pages.Document, bool) {
|
||||
for _, p := range s.Routes {
|
||||
if p.SiteRelPath() == relpath {
|
||||
return p, true
|
||||
@ -103,14 +103,12 @@ func (s *Site) RelPathPage(relpath string) (pages.Document, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// RelativeFilenameToURL returns a page's relative URL, give a file path relative to the site source directory.
|
||||
func (s *Site) RelativeFilenameToURL(relpath string) (string, bool) {
|
||||
var url string
|
||||
p, found := s.RelPathPage(relpath)
|
||||
if found {
|
||||
url = p.Permalink()
|
||||
// FilenameURLPath returns a page's URL path, give a relative file path relative to the site source directory.
|
||||
func (s *Site) FilenameURLPath(relpath string) (string, bool) {
|
||||
if p, found := s.FilePathPage(relpath); found {
|
||||
return p.Permalink(), true
|
||||
}
|
||||
return url, found
|
||||
return "", false
|
||||
}
|
||||
|
||||
// RenderingPipeline returns the rendering pipeline.
|
||||
@ -131,7 +129,7 @@ func (c pluginContext) TemplateEngine() liquid.Engine { return c.engine }
|
||||
// initializeRenderingPipeline initializes the rendering pipeline
|
||||
func (s *Site) initializeRenderingPipeline() (err error) {
|
||||
options := pipelines.PipelineOptions{
|
||||
RelativeFilenameToURL: s.RelativeFilenameToURL,
|
||||
RelativeFilenameToURL: s.FilenameURLPath,
|
||||
}
|
||||
s.pipeline, err = pipelines.NewPipeline(s.config, options)
|
||||
ctx := pluginContext{s.pipeline.TemplateEngine()}
|
||||
|
@ -9,7 +9,11 @@ import (
|
||||
)
|
||||
|
||||
func (tc tagContext) includeTag(w io.Writer, ctx chunks.RenderContext) error {
|
||||
args, err := ParseArgs(ctx.TagArgs())
|
||||
argsline, err := ctx.ParseTagArgs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
args, err := ParseArgs(argsline)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -24,5 +28,4 @@ func (tc tagContext) includeTag(w io.Writer, ctx chunks.RenderContext) error {
|
||||
ctx2 := ctx.Clone()
|
||||
ctx2.UpdateBindings(map[string]interface{}{"include": include})
|
||||
return ctx2.RenderFile(w, filename)
|
||||
|
||||
}
|
||||
|
23
tags/tags.go
23
tags/tags.go
@ -3,6 +3,7 @@ package tags
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path"
|
||||
|
||||
"github.com/osteele/gojekyll/config"
|
||||
"github.com/osteele/liquid"
|
||||
@ -19,10 +20,11 @@ func AddJekyllTags(e liquid.Engine, c config.Config, lh LinkTagHandler) {
|
||||
e.DefineTag("include", tc.includeTag)
|
||||
|
||||
// TODO unimplemented
|
||||
e.DefineTag("post_url", MakeUnimplementedTag())
|
||||
e.DefineTag("post_url", tc.postURLTag)
|
||||
e.DefineStartTag("highlight", highlightTag)
|
||||
}
|
||||
|
||||
// tagContext provides the context to a tag renderer.
|
||||
type tagContext struct {
|
||||
config config.Config
|
||||
lh LinkTagHandler
|
||||
@ -50,3 +52,22 @@ func (tc tagContext) linkTag(w io.Writer, ctx chunks.RenderContext) error {
|
||||
_, err := w.Write([]byte(url))
|
||||
return err
|
||||
}
|
||||
|
||||
func (tc tagContext) postURLTag(w io.Writer, ctx chunks.RenderContext) error {
|
||||
var (
|
||||
filename = ctx.TagArgs()
|
||||
found = false
|
||||
url string
|
||||
)
|
||||
for _, ext := range append(tc.config.MarkdownExtensions(), ",") {
|
||||
url, found = tc.lh(path.Join("_posts", filename+ext))
|
||||
if found {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
return fmt.Errorf("missing post_url filename: %s", filename)
|
||||
}
|
||||
_, err := w.Write([]byte(url))
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user