Browse Source

Sort tag/category page by date

Fix #75
index-subcmd
Vincent Prouillet 7 years ago
parent
commit
ffe8a24333
5 changed files with 25 additions and 6 deletions
  1. +4
    -0
      CHANGELOG.md
  2. +5
    -0
      README.md
  3. +12
    -5
      src/content/taxonomies.rs
  4. +4
    -0
      src/site.rs
  5. +0
    -1
      test_site/config.toml

+ 4
- 0
CHANGELOG.md View File

@@ -1,5 +1,9 @@
# Changelog # Changelog


## 0.0.7 (unreleased)

- Sort individual tag/category pages by date

## 0.0.6 (2017-05-24) ## 0.0.6 (2017-05-24)


- Fix missing serialized data for sections - Fix missing serialized data for sections


+ 5
- 0
README.md View File

@@ -135,6 +135,10 @@ You can also paginate section, including the index by setting the `paginate_by`
This represents the number of pages for each pager of the paginator. This represents the number of pages for each pager of the paginator.
You will need to access pages through the `paginator` object. (TODO: document that). You will need to access pages through the `paginator` object. (TODO: document that).


### Taxonomies: tags and categories

Individual tag/category pages are only supported for pages having a date.

### 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`.


@@ -223,6 +227,7 @@ In case of shortcodes with a body, the body will be passed as the `body` variabl




## Adding syntax highlighting languages and themes ## Adding syntax highlighting languages and themes

### Adding a syntax ### Adding a syntax
Syntax highlighting depends on submodules so ensure you load them first: Syntax highlighting depends on submodules so ensure you load them first:
```bash ```bash


+ 12
- 5
src/content/taxonomies.rs View File

@@ -6,6 +6,7 @@ use tera::{Context, Tera};
use config::Config; use config::Config;
use errors::{Result, ResultExt}; use errors::{Result, ResultExt};
use content::Page; use content::Page;
use content::sorting::{SortBy, sort_pages};




#[derive(Debug, Copy, Clone, PartialEq)] #[derive(Debug, Copy, Clone, PartialEq)]
@@ -24,10 +25,12 @@ pub struct TaxonomyItem {


impl TaxonomyItem { impl TaxonomyItem {
pub fn new(name: &str, pages: Vec<Page>) -> TaxonomyItem { pub fn new(name: &str, pages: Vec<Page>) -> TaxonomyItem {
// We shouldn't have any pages without dates there
let (sorted_pages, _) = sort_pages(pages, SortBy::Date);
TaxonomyItem { TaxonomyItem {
name: name.to_string(), name: name.to_string(),
slug: slugify(name), slug: slugify(name),
pages,
pages: sorted_pages,
} }
} }
} }
@@ -48,6 +51,14 @@ impl Taxonomy {


// Find all the tags/categories first // Find all the tags/categories first
for page in all_pages { for page in all_pages {
// Don't consider pages without pages for tags/categories as that's the only thing
// we can sort pages with across sections
// If anyone sees that comment and wonder wtf, please open an issue as I can't think of
// usecases other than blog posts for built-in taxonomies
if page.meta.date.is_none() {
continue;
}

if let Some(ref category) = page.meta.category { if let Some(ref category) = page.meta.category {
categories categories
.entry(category.to_string()) .entry(category.to_string())
@@ -109,10 +120,6 @@ impl Taxonomy {
let name = self.get_single_item_name(); let name = self.get_single_item_name();
let mut context = Context::new(); let mut context = Context::new();
context.add("config", config); context.add("config", config);
// TODO: how to sort categories and tag content?
// Have a setting in config.toml or a _category.md and _tag.md
// The latter is more in line with the rest of Gutenberg but order ordering
// doesn't really work across sections.
context.add(&name, item); context.add(&name, item);
context.add("current_url", &config.make_permalink(&format!("{}/{}", name, item.slug))); context.add("current_url", &config.make_permalink(&format!("{}/{}", name, item.slug)));
context.add("current_path", &format!("/{}/{}", name, item.slug)); context.add("current_path", &format!("/{}/{}", name, item.slug));


+ 4
- 0
src/site.rs View File

@@ -380,6 +380,10 @@ impl Site {
} }


fn render_taxonomy(&self, taxonomy: &Taxonomy) -> Result<()> { fn render_taxonomy(&self, taxonomy: &Taxonomy) -> Result<()> {
if taxonomy.items.is_empty() {
return Ok(())
}

ensure_directory_exists(&self.output_path)?; ensure_directory_exists(&self.output_path)?;


let output_path = self.output_path.join(&taxonomy.get_list_name()); let output_path = self.output_path.join(&taxonomy.get_list_name());


+ 0
- 1
test_site/config.toml View File

@@ -2,6 +2,5 @@ title = "My site"
base_url = "https://replace-this-with-your-url.com" base_url = "https://replace-this-with-your-url.com"
highlight_code = true highlight_code = true



[extra.author] [extra.author]
name = "Vincent Prouillet" name = "Vincent Prouillet"

Loading…
Cancel
Save