forked from jsonresume/resume-schema
-
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.
Merge pull request jsonresume#69 from ArmanMazdaee/add-render
Add render
- Loading branch information
Showing
22 changed files
with
591 additions
and
4,626 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module github.com/resumic/schema | ||
|
||
require ( | ||
github.com/gobuffalo/packd v0.0.0-20181124090624-311c6248e5fb | ||
github.com/gobuffalo/packr/v2 v2.0.0-rc.8 | ||
github.com/gohugoio/hugo v0.49.2 | ||
github.com/markbates/inflect v1.0.4 // indirect | ||
github.com/tidwall/gjson v1.1.3 | ||
github.com/tidwall/match v1.0.0 // indirect | ||
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect | ||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect | ||
github.com/xeipuuv/gojsonschema v0.0.0-20181112162635-ac52e6811b56 | ||
) |
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,87 @@ | ||
package render | ||
|
||
import ( | ||
"encoding/json" | ||
"io/ioutil" | ||
"os" | ||
"path" | ||
|
||
"github.com/gohugoio/hugo/commands" | ||
) | ||
|
||
type siteConfig struct { | ||
DisableKinds []string `json:"disableKinds"` | ||
Theme string `json:"theme"` | ||
} | ||
|
||
type frontmatter struct { | ||
Layout string `json:"layout"` | ||
} | ||
|
||
func build(root string) error { | ||
resp := commands.Execute([]string{"--quiet", "-s", root}) | ||
return resp.Err | ||
} | ||
|
||
func RenderHTML(resume []byte, theme string) ([]byte, error) { | ||
sitePath, err := ioutil.TempDir(os.TempDir(), "resumic") | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer os.RemoveAll(sitePath) | ||
|
||
themePath := path.Join(sitePath, "themes") | ||
err = extractTheme(themePath, theme) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
config := siteConfig{} | ||
config.Theme = theme | ||
config.DisableKinds = []string{"taxonomy", "taxonomyTerm", "category", "sitemap", "RSS", "404", "robotsTXT", "home", "section"} | ||
|
||
configJSON, err := json.MarshalIndent(config, "", " ") | ||
if err != nil { | ||
return nil, err | ||
} | ||
configPath := path.Join(sitePath, "config.json") | ||
err = ioutil.WriteFile(configPath, configJSON, 0600) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dataPath := path.Join(sitePath, "data", "resumic", "resume.json") | ||
err = os.MkdirAll(path.Dir(dataPath), 0700) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = ioutil.WriteFile(dataPath, resume, 0600) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
content := frontmatter{} | ||
content.Layout = "resumic" | ||
|
||
contentJSON, err := json.MarshalIndent(content, "", " ") | ||
if err != nil { | ||
return nil, err | ||
} | ||
contentPath := path.Join(sitePath, "content", "resumic", "resume.md") | ||
err = os.MkdirAll(path.Dir(contentPath), 0700) | ||
if err != nil { | ||
return nil, err | ||
} | ||
err = ioutil.WriteFile(contentPath, contentJSON, 0600) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = build(sitePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
htmlPath := path.Join(sitePath, "public", "resumic", "resume", "index.html") | ||
return ioutil.ReadFile(htmlPath) | ||
} |
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,41 @@ | ||
package render | ||
|
||
import ( | ||
"io" | ||
"os" | ||
"path" | ||
|
||
"github.com/gobuffalo/packd" | ||
packr "github.com/gobuffalo/packr/v2" | ||
) | ||
|
||
var themesList = map[string]bool{ | ||
"test-theme": true, | ||
} | ||
|
||
type InvalidThemeError struct { | ||
name string | ||
} | ||
|
||
func (e *InvalidThemeError) Error() string { | ||
return "render: " + e.name + " is not a valid theme." | ||
} | ||
|
||
func extractTheme(root, theme string) error { | ||
if !themesList[theme] { | ||
return &InvalidThemeError{name: theme} | ||
} | ||
|
||
box := packr.New("themes", "./render/themes") | ||
return box.WalkPrefix(theme+"/", func(name string, file packd.File) error { | ||
p := path.Join(root, name) | ||
os.MkdirAll(path.Dir(p), 0777) | ||
dst, err := os.Create(p) | ||
defer dst.Close() | ||
if err != nil { | ||
return err | ||
} | ||
_, err = io.Copy(dst, file) | ||
return err | ||
}) | ||
} |
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,6 @@ | ||
<html> | ||
<body> | ||
{{ $resume := index $.Site.Data.resumic .File.BaseFileName }} | ||
{{ $resume.core.name }} - {{ $resume.core.title }} | ||
</body> | ||
</html> |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.