Skip to content

Commit

Permalink
Added option to disable continuous html, updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Linus-Mussmaecher committed Jun 9, 2024
1 parent 184f305 commit fa3f5bc
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 36 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ From the select view, you can access a couple of file management options for you
- Reload the vault from the disk, in case you have made external changes.
When opening a note as described in the previous point, rucola will automatically reload that (and only that note), so this feature should not be neccessary to often.
- View the currently selected notes HTML representation in an external viewer.
The selected note (and only the selected note) will be converted to HTML just in time for that purpose, so following HTML links may not always work.
- Convert all currently filtered notes to HTML, so link following in the viewing feature above works as expected. Currently, you still need to do this manually whenever you have external changes to your files.

Additionally, rucola permanently tracks all file changes made through the program itself and by all external means and tries to keep the index up to date.
This includes edits to notes (updates links, word count, ...), moves & renames, creations and deletions.
This feature is currently untested on Windows.
Feel free to let me know if you are a Windows user on what works and what doesn't.


### Display Screen
Expand Down Expand Up @@ -168,18 +171,22 @@ This is especially useful for notes that are difficult to read, for example beca
HTML files are automatically prepended with a `.css`-stylesheet reference if you have configured a source CSS-file, and with a MathJax-preamble if they contain LaTeX-blocks (with either `$...$` or `$$...$$`).
Also, you can perform small-scale string replacements in math mode, for example replacing `\field` with `\mathbb` to write fields more semantically clearly.

You can view a single HTML file from the select screen or the display screen, in this case it is converted just-in-time.
You can view a single HTML file from the select screen or the display screen.
The file will be openend with the configured viewer (usually outside your terminal).
Alternatively, you can also convert all in the current local environment from the select view.
This allows you to follow links while viewing documents and is recommended.




### Configuration
Configuration files are - on Linux - stored in `XDG_CONFIGHOME/rucola`, which is usually `~/.config/rucola`.

Here is a list of all possible configuration settings:
- `dynamic_filter` is set to `true` by default, but can be set to `false` to cause your select view to only filter upon pressing enter and not while typing.
- `vault_path` is the path to your default vault that will be used by rucola unless overwritten by a command line positional argument.
- `file_types` lists all types of files to be indexed by rucola when opening a folder.
Per default, this is set to `["markdown"]`, tracking files with the extions `.md`, `.markdown`, ...
A full list of available file types can be found [here](https://docs.rs/ignore/latest/src/ignore/default_types.rs.html).
It is currently not possible to define your own file types.
- `default_extension` is the extension appended to notes created by rucola, `.md` by default.
- `theme` is the name of the `.toml`-theme file to configure rucola's visual appearance.
- `stats_show` is set to `Both` by default and configures which statistics blocks are shown at which time on the select screen.
It can have one of three values:
Expand All @@ -189,15 +196,14 @@ Here is a list of all possible configuration settings:
- `Relevant`: When you have no filter set, the global stats are shown.
Otherwise, local stats are shown.
This setting therefore avoids showing duplicating stats at all times.
- `default_extension` is the extension appended to notes created by rucola, `.md` by default.
- `file_types` lists all types of files to be indexed by rucola when opening a folder.
Per default, this is set to `["markdown"]`, tracking files with the extions `.md`, `.markdown`, ...
A full list of available file types can be found [here](https://docs.rs/ignore/latest/src/ignore/default_types.rs.html).
It is currently not possible to define your own file types.
- `continous_filter` is set to `true` by default, but can be set to `false` to cause your select view to only filter upon pressing enter and not while typing.
- `editor` configures the command to edit your notes.
This can be a terminal application or an external application.
- `viewer` configures the command for your HTML viewing application (I use `google-chrome-stable`). If unconfigured, tries to use your systems default application for HTML files.
- `mathjax` is set to `true` by default, but can be set to `false` to never prepend a MathJax preamble.
The following configuration options manage the HTML files created by rucola:
- `continuous_html` is set to `true` by default, causing all your notes to be converted to HTML files on program start and for those HTMLs to be continuously kept up-to-date in case of file changes.
Set to `false` to create HTMLs only on demand, which may cause links in them to be un-followable.
- `mathjax` is set to `true` by default, but can be set to `false` to never prepend a MathJax preamble to HTML files. While set to `true`, the preamble is only appended if math blocks (delimited by `$...$` and `$$...$$` are detected).
- `math_replacments` is a vector of pairs of strings.
In math mode, every appearance of the first string will be replaced by the second one.
The default replaces `field` with `mathbb` and `lieagl` with `mathfrak` as an example for the TOML syntax and the general idea of using semantically valuable string replacements to make your LaTeX code clearer.
Expand Down
39 changes: 23 additions & 16 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,30 @@ enum FilterShow {
/// Groups data passed by the user in the config file.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
struct ConfigFile {
/// Wether or not the select view filters while typing or only on enter.
dynamic_filter: bool,
/// Path to the vault to index.
vault_path: Option<path::PathBuf>,
/// Selected theme
theme: String,
/// When to show the global stats area
stats_show: FilterShow,
/// The editor to use for notes
editor: Option<String>,
/// File types to consider notes
/// See the [default list](https://docs.rs/ignore/latest/src/ignore/default_types.rs.html) of the ignore crate for possible options.
/// The "all" option matches all files.
file_types: Vec<String>,
/// Default file ending for newly created notes
default_extension: String,
/// String to prepend to all generated html documents (e.g. for MathJax)
html_prepend: Option<String>,
/// Path to .css file to style htmls with.
css: Option<String>,
/// Selected theme
theme: String,
/// When to show the global stats area
stats_show: FilterShow,
/// When set to true, the select screen filters while typing instead of only on enter.
continuous_filter: bool,
/// The editor to use for notes
editor: Option<String>,
/// Viewer to open html files with
viewer: Option<String>,
/// When set to true, HTML files are mass-created on start and continuously kept up to date with file changes instead of being created on-demand.
continuous_html: bool,
/// Path to .css file to style htmls with.
css: Option<String>,
/// String to prepend to all generated html documents (e.g. for MathJax)
html_prepend: Option<String>,
/// Wether or not to insert a MathJax preamble in notes containing math code.
mathjax: bool,
/// A list of strings to replace in math mode to mimic latex commands
Expand All @@ -47,7 +49,8 @@ struct ConfigFile {
impl Default for ConfigFile {
fn default() -> Self {
Self {
dynamic_filter: true,
continuous_filter: true,
continuous_html: true,
mathjax: true,
vault_path: if cfg!(test) {
Some(path::PathBuf::from("./tests/common/notes/"))
Expand Down Expand Up @@ -331,9 +334,13 @@ impl Config {
res
}

/// Returns the dynamic filtering option (wether to constantly refilter the selection list while the user types).
pub fn get_dynamic_filter(&self) -> bool {
self.config_file.dynamic_filter
/// Returns the current value of the continuous filter option.
pub fn continuous_filter_active(&self) -> bool {
self.config_file.continuous_filter
}
/// Returns the current value of the continuous filter option.
pub fn continuous_html_active(&self) -> bool {
self.config_file.continuous_html
}

/// Returns the default vault path.
Expand Down
20 changes: 14 additions & 6 deletions src/data/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ impl NoteIndex {
// Collect into hash map
.collect::<HashMap<_, _>>();

// create all htmls
for (_id, note) in inner.iter() {
let _ = super::notefile::create_html(note, config);
if config.continuous_html_active() {
// create all htmls
for (_id, note) in inner.iter() {
let _ = super::notefile::create_html(note, config);
}
}

Self { inner }
Expand Down Expand Up @@ -67,7 +69,9 @@ impl NoteIndex {
if config.is_tracked(&path) {
if let Ok(note) = super::Note::from_path(&path) {
// create html on creation
super::notefile::create_html(&note, config)?;
if config.continuous_html_active() {
super::notefile::create_html(&note, config)?;
}
// insert the note
self.inner.insert(super::name_to_id(&note.name), note);
modifications = true;
Expand All @@ -93,7 +97,9 @@ impl NoteIndex {
if config.is_tracked(&path) {
if let Ok(note) = super::Note::from_path(&path) {
// create html of new location
super::notefile::create_html(&note, config)?;
if config.continuous_html_active() {
super::notefile::create_html(&note, config)?;
}
// insert the note from the new location
self.inner.insert(super::name_to_id(&note.name), note);
modifications = true;
Expand All @@ -111,7 +117,9 @@ impl NoteIndex {
if event.paths.contains(&note.path) {
if let Ok(new_note) = Note::from_path(&note.path) {
// re-create html on modifications
super::notefile::create_html(&new_note, config)?;
if config.continuous_html_active() {
super::notefile::create_html(&new_note, config)?;
}
// replace the index entry
*note = new_note;
modifications = true;
Expand Down
4 changes: 2 additions & 2 deletions src/ui/screen/select_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,15 @@ impl super::Screen for SelectScreen {
// Escape or Enter: Back to main mode
KeyCode::Esc | KeyCode::Enter => {
self.mode = SelectMode::Select;
if key.code == KeyCode::Enter && !self.config.get_dynamic_filter() {
if key.code == KeyCode::Enter && !self.config.continuous_filter_active() {
self.filter(self.filter_from_input());
}
}
// All other key events are passed on to the text area, then the filter is immediately applied
_ => {
// Else -> Pass on to the text area
self.filter_area.input(key);
if self.config.get_dynamic_filter() {
if self.config.continuous_filter_active() {
self.filter(self.filter_from_input());
}
}
Expand Down

0 comments on commit fa3f5bc

Please sign in to comment.