Browse Source

Add a special section for home page

index-subcmd
Vincent Prouillet 7 years ago
parent
commit
df51e4d8b6
4 changed files with 25 additions and 7 deletions
  1. +7
    -3
      README.md
  2. +11
    -4
      src/site.rs
  3. +4
    -0
      test_site/content/_index.md
  4. +3
    -0
      tests/site.rs

+ 7
- 3
README.md View File

@@ -123,14 +123,18 @@ which template will be used to render that section.
Sections will also automatically pick up their subsections, allowing you to make some complex pages layout and Sections will also automatically pick up their subsections, allowing you to make some complex pages layout and
table of contents. table of contents.


A special case is the `_index.md` at the root of the `content` directory which represents the homepage. It is only there
to control pagination and sorting of the homepage.

### Code highlighting themes ### Code highlighting themes
Code highlighting can be turned on by setting `highlight_code = true` in `config.toml`. Code highlighting can be turned on by setting `highlight_code = true` in `config.toml`.


When turned on, all text between backticks will be highlighted, like the example below. When turned on, all text between backticks will be highlighted, like the example below.


```rust
let site = Site::new();
```
```rust
let site = Site::new();
```

If the name of the language is not given, it will default to plain-text highlighting. If the name of the language is not given, it will default to plain-text highlighting.


Gutenberg uses Sublime Text themes for syntax highlighting. It comes with the following theme Gutenberg uses Sublime Text themes for syntax highlighting. It comes with the following theme


+ 11
- 4
src/site.rs View File

@@ -64,6 +64,7 @@ pub struct Site {
pub config: Config, pub config: Config,
pub pages: HashMap<PathBuf, Page>, pub pages: HashMap<PathBuf, Page>,
pub sections: BTreeMap<PathBuf, Section>, pub sections: BTreeMap<PathBuf, Section>,
pub index: Option<Section>,
pub tera: Tera, pub tera: Tera,
live_reload: bool, live_reload: bool,
output_path: PathBuf, output_path: PathBuf,
@@ -91,6 +92,7 @@ impl Site {
config: get_config(path, config_file), config: get_config(path, config_file),
pages: HashMap::new(), pages: HashMap::new(),
sections: BTreeMap::new(), sections: BTreeMap::new(),
index: None,
tera: tera, tera: tera,
live_reload: false, live_reload: false,
output_path: path.join("public"), output_path: path.join("public"),
@@ -117,16 +119,21 @@ impl Site {
/// Reads all .md files in the `content` directory and create pages/sections /// Reads all .md files in the `content` directory and create pages/sections
/// out of them /// out of them
pub fn load(&mut self) -> Result<()> { pub fn load(&mut self) -> Result<()> {
let path = self.base_path.to_string_lossy().replace("\\", "/");
let content_glob = format!("{}/{}", path, "content/**/*.md");
let base_path = self.base_path.to_string_lossy().replace("\\", "/");
let content_glob = format!("{}/{}", base_path, "content/**/*.md");


// TODO: make that parallel, that's the main bottleneck // TODO: make that parallel, that's the main bottleneck
// `add_section` and `add_page` can't be used in the parallel version afaik // `add_section` and `add_page` can't be used in the parallel version afaik
for entry in glob(&content_glob).unwrap().filter_map(|e| e.ok()) { for entry in glob(&content_glob).unwrap().filter_map(|e| e.ok()) {
let path = entry.as_path(); let path = entry.as_path();

if path.file_name().unwrap() == "_index.md" { if path.file_name().unwrap() == "_index.md" {
self.add_section(path)?;
// Index section
if path.parent().unwrap() == self.base_path.join("content") {
self.index = Some(Section::from_file(path, &self.config)?);
} else {
// all the other sections
self.add_section(path)?;
}
} else { } else {
self.add_page(path)?; self.add_page(path)?;
} }


+ 4
- 0
test_site/content/_index.md View File

@@ -0,0 +1,4 @@
+++
title = "Home"
description = ""
+++

+ 3
- 0
tests/site.rs View File

@@ -22,6 +22,9 @@ fn test_can_parse_site() {
assert_eq!(site.pages.len(), 10); assert_eq!(site.pages.len(), 10);
let posts_path = path.join("content").join("posts"); let posts_path = path.join("content").join("posts");


// We have an index page
assert!(site.index.is_some());

// Make sure we remove all the pwd + content from the sections // Make sure we remove all the pwd + content from the sections
let basic = &site.pages[&posts_path.join("simple.md")]; let basic = &site.pages[&posts_path.join("simple.md")];
assert_eq!(basic.components, vec!["posts".to_string()]); assert_eq!(basic.components, vec!["posts".to_string()]);


Loading…
Cancel
Save