github.com/gohugoio/hugo@v0.88.1/commands/server_errors.go (about)

     1  // Copyright 2018 The Hugo Authors. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  // http://www.apache.org/licenses/LICENSE-2.0
     7  //
     8  // Unless required by applicable law or agreed to in writing, software
     9  // distributed under the License is distributed on an "AS IS" BASIS,
    10  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11  // See the License for the specific language governing permissions and
    12  // limitations under the License.
    13  
    14  package commands
    15  
    16  import (
    17  	"bytes"
    18  	"io"
    19  	"net/url"
    20  
    21  	"github.com/gohugoio/hugo/transform"
    22  	"github.com/gohugoio/hugo/transform/livereloadinject"
    23  )
    24  
    25  var buildErrorTemplate = `<!doctype html>
    26  <html class="no-js" lang="">
    27  	<head>
    28  		<meta charset="utf-8">
    29  		<title>Hugo Server: Error</title>
    30  		<style type="text/css">
    31  		body {
    32  			font-family: "Muli",avenir, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    33  			font-size: 16px;
    34  			background-color: #2f1e2e;
    35  		}
    36  		main {
    37  			margin: auto;
    38  			width: 95%;
    39  			padding: 1rem;
    40  		}		
    41  		.version {
    42  			color: #ccc;
    43  			padding: 1rem 0;
    44  		}
    45  		.stack {
    46  			margin-top: 4rem;
    47  		}
    48  		pre {
    49  			white-space: pre-wrap;      
    50  			white-space: -moz-pre-wrap;  
    51  			white-space: -pre-wrap;     
    52  			white-space: -o-pre-wrap;    
    53  			word-wrap: break-word;     
    54  		}
    55  		.highlight {
    56  			overflow-x: auto;
    57  			margin-bottom: 1rem;
    58  		}
    59  		a {
    60  			color: #0594cb;
    61  			text-decoration: none;
    62  		}
    63  		a:hover {
    64  			color: #ccc;
    65  		}
    66  		</style>
    67  	</head>
    68  	<body>
    69  		<main>
    70  			{{ highlight .Error "apl" "linenos=false,noclasses=true,style=paraiso-dark" }}
    71  			{{ with .File }}
    72  			{{ $params := printf "noclasses=true,style=paraiso-dark,linenos=table,hl_lines=%d,linenostart=%d" (add .LinesPos 1) (sub .Position.LineNumber .LinesPos) }}
    73  			{{ $lexer := .ChromaLexer | default "go-html-template" }}
    74  			{{  highlight (delimit .Lines "\n") $lexer $params }}
    75  			{{ end }}
    76  			{{ with .StackTrace }}
    77  			{{ highlight . "apl" "noclasses=true,style=paraiso-dark" }}
    78  			{{ end }}
    79  			<p class="version">{{ .Version }}</p>
    80  			<a href="">Reload Page</a>
    81  		</main>
    82  </body>
    83  </html>
    84  `
    85  
    86  func injectLiveReloadScript(src io.Reader, baseURL url.URL) string {
    87  	var b bytes.Buffer
    88  	chain := transform.Chain{livereloadinject.New(baseURL)}
    89  	chain.Apply(&b, src)
    90  
    91  	return b.String()
    92  }