github.com/jason-dour/hugo@v0.63.3/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  
    20  	"github.com/gohugoio/hugo/transform"
    21  	"github.com/gohugoio/hugo/transform/livereloadinject"
    22  )
    23  
    24  var buildErrorTemplate = `<!doctype html>
    25  <html class="no-js" lang="">
    26  	<head>
    27  		<meta charset="utf-8">
    28  		<title>Hugo Server: Error</title>
    29  		<style type="text/css">
    30  		body {
    31  			font-family: "Muli",avenir, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    32  			font-size: 16px;
    33  			background-color: black;
    34  			color: rgba(255, 255, 255, 0.9);
    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: 6rem;
    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  			padding: 0.75rem;
    58  			margin-bottom: 1rem;
    59  			background-color: #272822;
    60  			border: 1px solid black;
    61  		}
    62  		a {
    63  			color: #0594cb;
    64  			text-decoration: none;
    65  		}
    66  		a:hover {
    67  			color: #ccc;
    68  		}
    69  		</style>
    70  	</head>
    71  	<body>
    72  		<main>
    73  			{{ highlight .Error "apl" "noclasses=true,style=monokai" }}
    74  			{{ with .File }}
    75  			{{ $params := printf "noclasses=true,style=monokai,linenos=table,hl_lines=%d,linenostart=%d" (add .LinesPos 1) (sub .Position.LineNumber .LinesPos) }}
    76  			{{ $lexer := .ChromaLexer | default "go-html-template" }}
    77  			{{  highlight (delimit .Lines "\n") $lexer $params }}
    78  			{{ end }}
    79  			{{ with .StackTrace }}
    80  			{{ highlight . "apl" "noclasses=true,style=monokai" }}
    81  			{{ end }}
    82  			<p class="version">{{ .Version }}</p>
    83  			<a href="">Reload Page</a>
    84  		</main>
    85  </body>
    86  </html>
    87  `
    88  
    89  func injectLiveReloadScript(src io.Reader, port int) string {
    90  	var b bytes.Buffer
    91  	chain := transform.Chain{livereloadinject.New(port)}
    92  	chain.Apply(&b, src)
    93  
    94  	return b.String()
    95  }