-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Page references no longer include the path or scheme.
- Loading branch information
Showing
18 changed files
with
229 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Overview | ||
|
||
This is a command-line example that'll produce a tiny, functioning static website with multiple sub-pages and embedded images. | ||
|
||
# Running | ||
|
||
``` | ||
$ go run main.go --output-path output | ||
``` | ||
|
||
Then, open `output/index.html` from your browser. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"path" | ||
|
||
"github.com/dsoprea/go-logging" | ||
"github.com/jessevdk/go-flags" | ||
|
||
"github.com/dsoprea/go-static-site-builder" | ||
"github.com/dsoprea/go-static-site-builder/markdown" | ||
) | ||
|
||
type rootParameters struct { | ||
OutputPath string `long:"output-path" description:"Path to write to" required:"true"` | ||
} | ||
|
||
var ( | ||
rootArguments = new(rootParameters) | ||
) | ||
|
||
func main() { | ||
defer func() { | ||
if state := recover(); state != nil { | ||
err := log.Wrap(state.(error)) | ||
log.PrintError(err) | ||
os.Exit(-1) | ||
} | ||
}() | ||
|
||
p := flags.NewParser(rootArguments, flags.Default) | ||
|
||
_, err := p.Parse() | ||
if err != nil { | ||
os.Exit(1) | ||
} | ||
|
||
sc := sitebuilder.NewSiteContext(rootArguments.OutputPath) | ||
md := markdowndialect.NewMarkdownDialect() | ||
|
||
sb := sitebuilder.NewSiteBuilder("Site Title", md, sc) | ||
|
||
// Create content on root page. | ||
|
||
rootNode := sb.Root() | ||
rootPb := rootNode.Builder() | ||
|
||
erl1, err := sitebuilder.NewEmbeddedResourceLocator(path.Join("asset", "image1.jpg"), "", false) | ||
log.PanicIf(err) | ||
|
||
iw := sitebuilder.NewImageWidget("image alt text 1", erl1, 100, 100) | ||
|
||
err = rootPb.AddContentImage(iw) | ||
log.PanicIf(err) | ||
|
||
// Add a new page. | ||
|
||
childNode1, err := rootNode.AddChildNode("child1", "Child Page 1") | ||
log.PanicIf(err) | ||
|
||
childPb := childNode1.Builder() | ||
|
||
erl2, err := sitebuilder.NewEmbeddedResourceLocator(path.Join("asset", "image2.jpg"), "", false) | ||
log.PanicIf(err) | ||
|
||
iw = sitebuilder.NewImageWidget("image alt text 2", erl2, 100, 100) | ||
|
||
err = childPb.AddContentImage(iw) | ||
log.PanicIf(err) | ||
|
||
// Add a new page. | ||
|
||
childNode2, err := rootNode.AddChildNode("child2", "Child Page 2") | ||
log.PanicIf(err) | ||
|
||
childPb = childNode2.Builder() | ||
|
||
erl3, err := sitebuilder.NewEmbeddedResourceLocator(path.Join("asset", "image3.jpg"), "", false) | ||
log.PanicIf(err) | ||
|
||
iw = sitebuilder.NewImageWidget("image alt text 3", erl3, 100, 100) | ||
|
||
err = childPb.AddContentImage(iw) | ||
log.PanicIf(err) | ||
|
||
items := []sitebuilder.LinkWidget{ | ||
sitebuilder.NewLinkWidget("Child1", sitebuilder.NewSitePageLocalResourceLocator(sb, "child1")), | ||
sitebuilder.NewLinkWidget("Child2", sitebuilder.NewSitePageLocalResourceLocator(sb, "child2")), | ||
} | ||
|
||
nw := sitebuilder.NewNavbarWidget(items) | ||
|
||
err = rootPb.AddNavbar(nw) | ||
log.PanicIf(err) | ||
|
||
// Render and write. | ||
|
||
err = sb.WriteToPath() | ||
log.PanicIf(err) | ||
|
||
// // Print. | ||
|
||
// files, err := ioutil.ReadDir(tempPath) | ||
// log.PanicIf(err) | ||
|
||
// for _, fi := range files { | ||
// filename := fi.Name() | ||
|
||
// fmt.Printf("%s\n", filename) | ||
// fmt.Printf("====================\n") | ||
// fmt.Printf("\n") | ||
|
||
// filepath := path.Join(tempPath, filename) | ||
// content, err := ioutil.ReadFile(filepath) | ||
// log.PanicIf(err) | ||
|
||
// // For the [testable] example. | ||
// fixedContent := strings.Replace(string(content), tempPath, "example_path", -1) | ||
|
||
// _, err = os.Stdout.Write([]byte(fixedContent)) | ||
// log.PanicIf(err) | ||
|
||
// fmt.Printf("\n") | ||
// } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"os/exec" | ||
"testing" | ||
|
||
"github.com/dsoprea/go-logging" | ||
) | ||
|
||
func TestMain(t *testing.T) { | ||
tempPath, err := ioutil.TempDir("", "") | ||
log.PanicIf(err) | ||
|
||
cmd := exec.Command("go", "run", "main.go", "--output-path", tempPath) | ||
|
||
err = cmd.Run() | ||
log.PanicIf(err) | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.