summaryrefslogtreecommitdiffstats
path: root/.gitignore
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-03-03 12:25:03 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-04-09 22:57:26 +0200
commit095bf64c99f57efe083540a50e658808a0a1c32b (patch)
tree18d3ffb1701250ca5ef3caa2073214b6b9aff6f1 /.gitignore
parent7791a804e2179667617b3b145b0fe7eba17627a1 (diff)
Collect HTML elements during the build to use in PurgeCSS etc.
The main use case for this is to use with resources.PostProcess and resources.PostCSS with purgecss. You would normally set it up to extract keywords from your templates, doing it from the full /public takes forever for bigger sites. Doing the template thing misses dynamically created class names etc., and it's hard/impossible to set up in when using themes. You can enable this in your site config: ```toml [build] writeStats = true ``` It will then write a `hugo_stats.json` file to the project root as part of the build. If you're only using this for the production build, you should consider putting it below `config/production`. You can then set it up with PostCSS like this: ```js const purgecss = require('@fullhuman/postcss-purgecss')({ content: [ './hugo_stats.json' ], defaultExtractor: (content) => { let els = JSON.parse(content).htmlElements; return els.tags.concat(els.classes, els.ids); } }); module.exports = { plugins: [ require('tailwindcss'), require('autoprefixer'), ...(process.env.HUGO_ENVIRONMENT === 'production' ? [ purgecss ] : []) ] }; ``` Fixes #6999
Diffstat (limited to '.gitignore')
-rw-r--r--.gitignore1
1 files changed, 1 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 75d85e8d0..d3ef01991 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@ dock.sh
GoBuilds
dist
+hugolib/hugo_stats.json
resources/sunset.jpg
vendor
w"> -> AppStateCmdResult { AppStateCmdResult::from_optional_state( BrowserState::new( path, tree.options.clone(), screen, &TaskLifetime::unlimited(), ), Command::from(&tree.options.pattern), ) } impl VerbExecutor for BrowserState { fn execute_verb( &mut self, verb: &Verb, invocation: &VerbInvocation, screen: &mut Screen, con: &AppContext, ) -> Result<AppStateCmdResult, ProgramError> { if let Some(err) = verb.match_error(invocation) { return Ok(AppStateCmdResult::DisplayError(err)); } let page_height = BrowserState::page_height(screen); Ok(match verb.execution.as_ref() { ":back" => AppStateCmdResult::PopState, ":focus" => { let tree = self.displayed_tree_mut(); let line = &tree.selected_line(); let mut path = line.target(); if !path.is_dir() { path = path.parent().unwrap().to_path_buf(); } focus_path(path, screen, tree) } ":focus_root" => focus_path(PathBuf::from("/"), screen, self.displayed_tree()), ":up_tree" => match self.displayed_tree().root().parent() { Some(path) => focus_path(path.to_path_buf(), screen, self.displayed_tree()), None => AppStateCmdResult::DisplayError("no parent found".to_string()), }, ":focus_user_home" => match UserDirs::new() { Some(ud) => focus_path(ud.home_dir().to_path_buf(), screen, self.displayed_tree()), None => AppStateCmdResult::DisplayError("no user home directory found".to_string()), }, ":help" => { AppStateCmdResult::NewState(Box::new(HelpState::new(screen, con)), Command::new()) } ":open_stay" => self.open_selection_stay_in_broot(screen, con)?, ":open_leave" => self.open_selection_quit_broot(screen, con)?, ":line_down" => { self.displayed_tree_mut().move_selection(1, page_height); AppStateCmdResult::Keep } ":line_up" => { self.displayed_tree_mut().move_selection(-1, page_height); AppStateCmdResult::Keep } ":page_down" => { let tree = self.displayed_tree_mut(); if page_height < tree.lines.len() as i32 { tree.try_scroll(page_height, page_height); } AppStateCmdResult::Keep } ":page_up" => { let tree = self.displayed_tree_mut(); if page_height < tree.lines.len() as i32 { tree.try_scroll(-page_height, page_height); } AppStateCmdResult::Keep } ":parent" => match &self.displayed_tree().selected_line().path.parent() { Some(path) => AppStateCmdResult::from_optional_state( BrowserState::new( path.to_path_buf(), self.displayed_tree().options.without_pattern(), screen, &TaskLifetime::unlimited(), ), Command::new(), ), None => AppStateCmdResult::DisplayError("no parent found".to_string()), }, ":print_path" => { external::print_path(&self.displayed_tree().selected_line().target(), con)? } ":print_tree" => external::print_tree(&self.displayed_tree(), screen, con)?, ":refresh" => AppStateCmdResult::RefreshState { clear_cache: true }, ":select_first" => { self.displayed_tree_mut().try_select_first(); AppStateCmdResult::Keep } ":select_last" => { self.displayed_tree_mut().try_select_last(); AppStateCmdResult::Keep } ":toggle_dates" => self.with_new_options(screen, &|o| o.show_dates ^= true), ":toggle_files" => { self.with_new_options(screen, &|o: &mut TreeOptions| o.only_folders ^= true) } ":toggle_hidden" => self.with_new_options(screen, &|o| o.show_hidden ^= true), ":toggle_git_ignore" => self.with_new_options(screen, &|options| { options.respect_git_ignore = match options.respect_git_ignore { OptionBool::Auto => { if self.displayed_tree().nb_gitignored > 0 { OptionBool::No } else { OptionBool::Yes } } OptionBool::Yes => OptionBool::No, OptionBool::No => OptionBool::Yes, }; }), ":toggle_perm" => self.with_new_options(screen, &|o| o.show_permissions ^= true), ":toggle_sizes" => self.with_new_options(screen, &|o| o.show_sizes ^= true), ":toggle_trim_root" => self.with_new_options(screen, &|o| o.trim_root ^= true), ":total_search" => { if let Some(tree) = &self.filtered_tree { if tree.total_search { AppStateCmdResult::DisplayError( "search was already total - all children have been rated".to_owned(), ) } else { self.pending_pattern = tree.options.pattern.clone(); self.total_search_required = true; AppStateCmdResult::Keep } } else { AppStateCmdResult::DisplayError( "this verb can be used only after a search".to_owned(), ) } } ":quit" => AppStateCmdResult::Quit, _ => verb.to_cmd_result( &self.displayed_tree().selected_line().path.clone(), &invocation.args, screen, con, )?, }) } }