mirror of
https://github.com/danog/gojekyll.git
synced 2025-01-23 03:21:15 +01:00
Zero the url when serving
This commit is contained in:
parent
67d4fd15a4
commit
f44eeb8b68
@ -24,6 +24,7 @@ type Server struct {
|
|||||||
|
|
||||||
// Run runs the server.
|
// Run runs the server.
|
||||||
func (s *Server) Run(open bool, logger func(label, value string)) error {
|
func (s *Server) Run(open bool, logger func(label, value string)) error {
|
||||||
|
s.Site.SetAbsoluteURL("")
|
||||||
err := s.Site.InitializeRenderingPipeline()
|
err := s.Site.InitializeRenderingPipeline()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -54,10 +55,12 @@ func (s *Server) handler(rw http.ResponseWriter, r *http.Request) {
|
|||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
|
|
||||||
site := s.Site
|
var (
|
||||||
urlpath := r.URL.Path
|
site = s.Site
|
||||||
|
urlpath = r.URL.Path
|
||||||
|
)
|
||||||
p, found := site.URLPage(urlpath)
|
p, found := site.URLPage(urlpath)
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
rw.WriteHeader(http.StatusNotFound)
|
rw.WriteHeader(http.StatusNotFound)
|
||||||
log.Println("Not found:", urlpath)
|
log.Println("Not found:", urlpath)
|
||||||
@ -92,5 +95,6 @@ func (s *Server) reloadSite() {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
}
|
}
|
||||||
|
s.Site.SetAbsoluteURL("")
|
||||||
fmt.Printf("reloaded in %.2fs\n", time.Since(start).Seconds())
|
fmt.Printf("reloaded in %.2fs\n", time.Since(start).Seconds())
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,14 @@ func NewSiteFromDirectory(source string) (*Site, error) {
|
|||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetAbsoluteURL overrides the loaded configuration.
|
||||||
|
// The server uses this.
|
||||||
|
func (s *Site) SetAbsoluteURL(url string) {
|
||||||
|
s.config.AbsoluteURL = url
|
||||||
|
s.config.Variables["url"] = url
|
||||||
|
s.Variables["url"] = url
|
||||||
|
}
|
||||||
|
|
||||||
// FilenameURLs returns a map of relative filenames to URL paths
|
// FilenameURLs returns a map of relative filenames to URL paths
|
||||||
func (s *Site) FilenameURLs() map[string]string {
|
func (s *Site) FilenameURLs() map[string]string {
|
||||||
urls := map[string]string{}
|
urls := map[string]string{}
|
||||||
@ -108,10 +116,11 @@ func (s *Site) RenderingPipeline() pipelines.PipelineInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// InitializeRenderingPipeline initializes the rendering pipeline
|
// InitializeRenderingPipeline initializes the rendering pipeline
|
||||||
func (s *Site) InitializeRenderingPipeline() (err error) {
|
func (s *Site) InitializeRenderingPipeline() error {
|
||||||
o := pipelines.PipelineOptions{UseRemoteLiquidEngine: s.UseRemoteLiquidEngine}
|
o := pipelines.PipelineOptions{UseRemoteLiquidEngine: s.UseRemoteLiquidEngine}
|
||||||
|
var err error
|
||||||
s.pipeline, err = pipelines.NewPipeline(s.Source, s.config, s, o)
|
s.pipeline, err = pipelines.NewPipeline(s.Source, s.config, s, o)
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// OutputExt returns the output extension.
|
// OutputExt returns the output extension.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user