-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy only the static files changed #1671
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ import ( | |
|
||
"github.com/spf13/hugo/parser" | ||
|
||
"regexp" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/fsync" | ||
"github.com/spf13/hugo/helpers" | ||
|
@@ -40,7 +42,6 @@ import ( | |
"github.com/spf13/nitro" | ||
"github.com/spf13/viper" | ||
"gopkg.in/fsnotify.v1" | ||
"regexp" | ||
) | ||
|
||
// userError is an error used to signal different error situations in command handling. | ||
|
@@ -111,7 +112,7 @@ Complete documentation is available at http://gohugo.io/.`, | |
var hugoCmdV *cobra.Command | ||
|
||
// Flags that are to be added to commands. | ||
var BuildWatch, IgnoreCache, Draft, Future, UglyURLs, CanonifyURLs, Verbose, Logging, VerboseLog, DisableRSS, DisableSitemap, PluralizeListTitles, PreserveTaxonomyNames, NoTimes bool | ||
var BuildWatch, IgnoreCache, Draft, Future, UglyURLs, CanonifyURLs, Verbose, Logging, VerboseLog, DisableRSS, DisableSitemap, PluralizeListTitles, PreserveTaxonomyNames, NoTimes, ForceSync bool | ||
var Source, CacheDir, Destination, Theme, BaseURL, CfgFile, LogFile, Editor string | ||
|
||
// Execute adds all child commands to the root command HugoCmd and sets flags appropriately. | ||
|
@@ -171,7 +172,7 @@ func initCoreCommonFlags(cmd *cobra.Command) { | |
cmd.Flags().BoolVar(&nitro.AnalysisOn, "stepAnalysis", false, "display memory and timing of different steps of the program") | ||
cmd.Flags().BoolVar(&PluralizeListTitles, "pluralizeListTitles", true, "Pluralize titles in lists using inflect") | ||
cmd.Flags().BoolVar(&PreserveTaxonomyNames, "preserveTaxonomyNames", false, `Preserve taxonomy names as written ("Gérard Depardieu" vs "gerard-depardieu")`) | ||
|
||
cmd.Flags().BoolVarP(&ForceSync, "forceSyncStatic", "", false, "Copy all files when static is changed.") | ||
// For bash-completion | ||
validConfigFilenames := []string{"json", "js", "yaml", "yml", "toml", "tml"} | ||
cmd.Flags().SetAnnotation("config", cobra.BashCompFilenameExt, validConfigFilenames) | ||
|
@@ -236,6 +237,7 @@ func LoadDefaultSettings() { | |
viper.SetDefault("DisableLiveReload", false) | ||
viper.SetDefault("PluralizeListTitles", true) | ||
viper.SetDefault("PreserveTaxonomyNames", false) | ||
viper.SetDefault("ForceSyncStatic", false) | ||
viper.SetDefault("FootnoteAnchorPrefix", "") | ||
viper.SetDefault("FootnoteReturnLinkContents", "") | ||
viper.SetDefault("NewContentEditor", "") | ||
|
@@ -304,6 +306,9 @@ func InitializeConfig(subCmdVs ...*cobra.Command) error { | |
if cmdV.Flags().Lookup("preserveTaxonomyNames").Changed { | ||
viper.Set("PreserveTaxonomyNames", PreserveTaxonomyNames) | ||
} | ||
if cmdV.Flags().Lookup("forceSyncStatic").Changed { | ||
viper.Set("ForceSyncStatic", ForceSync) | ||
} | ||
if cmdV.Flags().Lookup("editor").Changed { | ||
viper.Set("NewContentEditor", Editor) | ||
} | ||
|
@@ -612,11 +617,40 @@ func NewWatcher(port int) error { | |
} | ||
|
||
if staticChanged { | ||
jww.FEEDBACK.Printf("Static file changed, syncing\n\n") | ||
err := copyStatic() | ||
if err != nil { | ||
fmt.Println(err) | ||
utils.StopOnErr(err, fmt.Sprintf("Error copying static files to %s", helpers.AbsPathify(viper.GetString("PublishDir")))) | ||
jww.FEEDBACK.Printf("Static file changed, syncing\n") | ||
if viper.GetBool("ForceSyncStatic") { | ||
jww.FEEDBACK.Printf("Syncing all static files\n") | ||
err := copyStatic() | ||
if err != nil { | ||
fmt.Println(err) | ||
utils.StopOnErr(err, fmt.Sprintf("Error copying static files to %s", helpers.AbsPathify(viper.GetString("PublishDir")))) | ||
} | ||
} else { | ||
|
||
syncer := fsync.NewSyncer() | ||
syncer.NoTimes = viper.GetBool("notimes") | ||
syncer.SrcFs = hugofs.SourceFs | ||
syncer.DestFs = hugofs.DestinationFS | ||
|
||
publishDir := helpers.AbsPathify(viper.GetString("PublishDir")) + "/" | ||
|
||
if publishDir == "//" || publishDir == "/" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
publishDir = "" | ||
} | ||
|
||
for path := range staticFilesChanged { | ||
staticPath := filepath.Join(helpers.AbsPathify(viper.GetString("StaticDir")), path) | ||
jww.FEEDBACK.Printf("Syncing file '%s'\n", staticPath) | ||
|
||
if _, err := os.Stat(staticPath); err == nil { | ||
publishPath := filepath.Join(publishDir, path) | ||
jww.INFO.Println("syncing from", staticPath, "to", publishPath) | ||
err := syncer.Sync(publishPath, staticPath) | ||
if err != nil { | ||
jww.FEEDBACK.Printf("Error on syncing file '%s'\n", staticPath) | ||
} | ||
} | ||
} | ||
} | ||
|
||
if !BuildWatch && !viper.GetBool("DisableLiveReload") { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
os file separator