Verified Commit c80904cf authored by Aral Balkan's avatar Aral Balkan
Browse files

Add basic hugo server feature

parent 81bb7181
Pipeline #915 failed with stages
......@@ -19,7 +19,11 @@
const hugo = new Hugo()
const command = process.argv[2]
if (command === 'build') {
//
// Hugo build.
//
const sourcePath = process.argv[3]
const destinationPath = process.argv[4]
if (!sourcePath || !destinationPath) {
......@@ -27,7 +31,8 @@
showUsage()
process.exit(1)
}
console.log(`\n[Hugo] Build. Source: ${sourcePath} Destination: ${destinationPath}\n`)
console.log(`\n[node-hugo] Build. Source: ${sourcePath} Destination: ${destinationPath}\n`)
let result
try {
......@@ -49,9 +54,21 @@
} else if (command === 'serve') {
//
// TODO
// Start Hugo server.
//
console.log('serve (todo)', process.argv[3])
const sourcePath = process.argv[3]
const destinationPath = process.argv[4]
const baseURL = process.argv[5]
if (!sourcePath || !destinationPath || !baseURL) {
console.log('\nError: Serve command requires <sourcePath>, <destinationPath>, and <baseURL> arguments')
showUsage()
process.exit(1)
}
console.log(`\n[node-hugo] Serve. Source: ${sourcePath} Destination: ${destinationPath} Base URL: ${baseURL}\n`)
hugo.serve(sourcePath, destinationPath, baseURL)
} else {
//
// Error.
......
......@@ -6,6 +6,7 @@ const util = require('util')
const childProcess = require('child_process')
const exec = util.promisify(childProcess.exec)
const spawn = childProcess.spawn
const homeDir = os.homedir()
......@@ -57,9 +58,25 @@ class Hugo {
return result.stdout
}
// Starts a Hugo server at the requested path to serve and returns the Hugo server instance.
async serve (pathToServe) {
throw new Error('Unimplemented.')
// Starts a Hugo server with defaults set for rendering to disk and using outside live reload.
// (These are the defaults our current use case on Site.js).
// hugo server --source=.hugo-source --destination=../.hugo-public --buildDrafts --renderToDisk --baseURL=https://localhost --disableLiveReload --appendPort=false
serve (sourcePath, destinationPath, baseURL) {
const args = [
'server',
`--source=${sourcePath}`,
`--destination=${destinationPath}`,
`--baseURL=${baseURL}`,
'--buildDrafts',
'--renderToDisk',
'--disableLiveReload',
'--appendPort=false',
]
const options = { env: process.env, stdio: 'inherit' }
const hugoServer = spawn(this.hugoBinaryPath, args, options)
return hugoServer
}
//
......
......@@ -2,12 +2,12 @@
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Categories on My New Hugo Site</title>
<link>http://example.org/categories/</link>
<link>https://localhost/categories/</link>
<description>Recent content in Categories on My New Hugo Site</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<atom:link href="http://example.org/categories/index.xml" rel="self" type="application/rss+xml" />
<atom:link href="https://localhost/categories/index.xml" rel="self" type="application/rss+xml" />
</channel>
......
Hello
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="generator" content="Hugo 0.64.0" />
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello, world!</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
\ No newline at end of file
......@@ -2,12 +2,12 @@
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>My New Hugo Site</title>
<link>http://example.org/</link>
<link>https://localhost/</link>
<description>Recent content on My New Hugo Site</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<atom:link href="http://example.org/index.xml" rel="self" type="application/rss+xml" />
<atom:link href="https://localhost/index.xml" rel="self" type="application/rss+xml" />
</channel>
......
......@@ -3,15 +3,15 @@
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>http://example.org/categories/</loc>
<loc>https://localhost/categories/</loc>
</url>
<url>
<loc>http://example.org/</loc>
<loc>https://localhost/</loc>
</url>
<url>
<loc>http://example.org/tags/</loc>
<loc>https://localhost/tags/</loc>
</url>
</urlset>
\ No newline at end of file
......@@ -2,12 +2,12 @@
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Tags on My New Hugo Site</title>
<link>http://example.org/tags/</link>
<link>https://localhost/tags/</link>
<description>Recent content in Tags on My New Hugo Site</description>
<generator>Hugo -- gohugo.io</generator>
<language>en-us</language>
<atom:link href="http://example.org/tags/index.xml" rel="self" type="application/rss+xml" />
<atom:link href="https://localhost/tags/index.xml" rel="self" type="application/rss+xml" />
</channel>
......
Hello
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello, world!</title>
</head>
<body>
<p>Hello, world!</p>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment