Skip to content

Commit

Permalink
Add assets dir (Fix #6).
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed May 15, 2020
1 parent 26dc48c commit 4b101df
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func Build() {
// Directly copy .js that don't need compiling to the build dir.
build.EjectCopy(buildPath)

// Directly copy static assets to the build dir.
build.AssetsCopy(buildPath)

// Build JSON from "content/" directory.
staticBuildStr, allNodesStr := build.DataSource(buildPath, siteConfig)

Expand Down
53 changes: 53 additions & 0 deletions cmd/build/assets_copy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package build

import (
"fmt"
"io"
"os"
"path/filepath"
"strconv"
"time"
)

// AssetsCopy does a direct copy of any static assets.
func AssetsCopy(buildPath string) {

defer Benchmark(time.Now(), "Copying static assets into build dir")

Log("\nCopying static assets:")

copiedSourceCounter := 0

assetFilesErr := filepath.Walk("assets", func(assetPath string, assetFileInfo os.FileInfo, err error) error {
destPath := buildPath + "/" + assetPath
if assetFileInfo.IsDir() {
// Make directory if it doesn't exist.
os.MkdirAll(destPath, os.ModePerm)
}
from, err := os.Open(assetPath)
if err != nil {
fmt.Printf("Could not open asset for copying: %s\n", err)
}
defer from.Close()

to, err := os.Create(destPath)
if err != nil {
fmt.Printf("Could not create destination asset for copying: %s\n", err)
}
defer to.Close()

_, fileCopyErr := io.Copy(to, from)
if err != nil {
fmt.Printf("Could not copy asset from source to destination: %s\n", fileCopyErr)
}

copiedSourceCounter++
return nil
})
if assetFilesErr != nil {
fmt.Printf("Could not get asset file: %s", assetFilesErr)
}

Log("Number of assets copied: " + strconv.Itoa(copiedSourceCounter))

}
3 changes: 3 additions & 0 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func Watch(buildPath string) {
if err := filepath.Walk("layout", watchDir(buildPath)); err != nil {
fmt.Println("Error watching 'layout/' folder for changes: ", err)
}
if err := filepath.Walk("assets", watchDir(buildPath)); err != nil {
fmt.Println("Error watching 'assets/' folder for changes: ", err)
}
watcher.Add("plenti.json")
watcher.Add("package.json")

Expand Down
35 changes: 35 additions & 0 deletions defaults/assets/plenti.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion defaults/layout/global/head.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
<title>{ title }</title>

<link href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300;0,700;1,300&display=swap" rel="stylesheet">
<link rel='icon' type='image/png' href='/favicon.png'>
<link rel="icon" type="image/svg+xml" href="/assets/plenti.svg">
<link rel='stylesheet' href='/spa/bundle.css'>
</head>
38 changes: 37 additions & 1 deletion generated/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@ package generated
var Defaults = map[string][]byte{
"/.gitignore": []byte(`public
node_modules`),
"/assets/plenti.svg": []byte(`<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg width="37.351mm" height="37.351mm" version="1.1" viewBox="0 0 37.351 37.351" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<metadata>
<rdf:RDF>
<cc:Work rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage"/>
<dc:title/>
</cc:Work>
</rdf:RDF>
</metadata>
<g transform="matrix(.82125 0 0 1 .85644 -.52917)">
<path d="m21.648 4.5162c-6.3412 0-11.886 2.2425-14.906 5.5881-1.7071 1.4294-4.6948 3.0274-6.3451 4.8992-2.1067 2.5006 4.8512 4.0176 4.9355 3.5132 3.2924 7.4995 9.9448 15.539 16.316 15.659 5.2012-0.66288 14.869-8.8176 16.935-15.905 1.5388-0.33171 5.0941-0.36828 4.2394-3.2676-0.77538-0.96414-6.2242-4.8903-6.3267-4.9642-3.0333-3.3098-8.5479-5.5232-14.848-5.5232z" fill="#22a6ed" fill-rule="evenodd"/>
<path d="m21.648 4.5162c-9.5704 0-17.329 5.1073-17.329 11.407 2.7439 8.1059 10.214 18.118 17.329 18.252 5.7885-0.73775 17.111-10.755 17.329-18.252 0-6.3002-7.7583-11.407-17.329-11.407z" fill="none"/>
<g transform="translate(-45.832 -105.33)" fill-rule="evenodd">
<path d="m55.19 130.96c-1.486-2.0735 7.8403 7.0493 12.324 7.0871 4.8974-0.29154 13.838-8.7206 12.619-7.2432-1.1598 1.7268-7.6713 8.6765-12.652 8.7053-5.4222-0.0543-10.702-6.333-12.29-8.5492z" fill="#1c7fc7"/>
<path d="m77.069 125.83c0-0.0211 0.36697 4.1258-3.4253 4.8676-3.7923-0.15207-4.1593-4.7915-4.1593-4.7915z" fill="#1c7fc7"/>
<path d="m77.604 123.27a4.21 6.6213 0 0 1-4.2101 6.6213 4.21 6.6213 0 0 1-4.21-6.6213 4.21 6.6213 0 0 1 4.21-6.6213 4.21 6.6213 0 0 1 4.2101 6.6213z" fill="#fff"/>
<path d="m57.792 125.85c0-8e-3 -0.36697 4.0827 3.4253 4.8676 3.7923-0.15206 4.0981-4.9436 4.0981-4.9436z" fill="#1c7fc7"/>
<path d="m65.693 123.27a4.21 6.6213 0 0 1-4.2101 6.6213 4.21 6.6213 0 0 1-4.21-6.6213 4.21 6.6213 0 0 1 4.21-6.6213 4.21 6.6213 0 0 1 4.2101 6.6213z" fill="#fff"/>
</g>
<g transform="translate(-45.832 -105.33)" fill="#082f58" fill-rule="evenodd">
<path d="m50.843 120.04c-0.81738 0.19161-2.8496 0.96099-2.4963 1.4176 0.34641 0.28078 2.6716 1.5627 2.6692 0.71228 0-0.74229 0.18804-2.2145-0.17296-2.1299z"/>
<ellipse cx="62.85" cy="123.67" rx="2.4372" ry="3.0305"/>
<ellipse cx="71.874" cy="123.67" rx="2.4372" ry="3.0305"/>
</g>
<path d="m21.648 4.5162c-6.3412 0-11.886 2.2425-14.906 5.5881l0.01481-0.089s-5.5771 4.015-6.3599 4.9882c-1.1253 3.8172 3.3221 2.5642 4.8924 3.7712l0.04313-0.25809c3.2924 7.4995 9.9448 15.539 16.316 15.659 5.2012-0.66288 14.869-8.8176 16.935-15.905 1.5388-0.33171 5.0941-0.36828 4.2394-3.2676-0.77538-0.96414-6.2242-4.8903-6.3267-4.9642-3.0333-3.3098-8.5479-5.5232-14.848-5.5232z" fill="none"/>
<g transform="translate(-45.832 -105.33)" fill-rule="evenodd">
<path d="m84.158 119.72c0.81738 0.19161 2.8497 0.96099 2.4963 1.4176-0.34641 0.28078-2.6716 1.5627-2.6692 0.71228 0-0.74229-0.18804-2.2145 0.17296-2.1299z" fill="#082f58"/>
<ellipse cx="70.913" cy="122.84" rx=".75036" ry=".93304" fill="#fff"/>
<ellipse cx="62.092" cy="122.84" rx=".75036" ry=".93304" fill="#fff"/>
</g>
</g>
</svg>
`),
"/content/blog/_blueprint.json": []byte(`{
"title": "text",
"body": ["text"],
Expand Down Expand Up @@ -254,7 +290,7 @@ node_modules`),
<title>{ title }</title>
<link href="https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300;0,700;1,300&display=swap" rel="stylesheet">
<link rel='icon' type='image/png' href='/favicon.png'>
<link rel="icon" type="image/svg+xml" href="/assets/plenti.svg">
<link rel='stylesheet' href='/spa/bundle.css'>
</head>
`),
Expand Down

0 comments on commit 4b101df

Please sign in to comment.