Update slotmap
This commit is contained in:
parent
4fd5d3f348
commit
5844047435
480
Cargo.lock
generated
480
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
|||
authors = ["Vincent Prouillet <prouillet.vincent@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
slotmap = "0.2"
|
||||
slotmap = "0.4"
|
||||
rayon = "1"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
tera = "1.0.0-beta.10"
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use regex::Regex;
|
||||
use slotmap::Key;
|
||||
use slotmap::DefaultKey;
|
||||
use slug::slugify;
|
||||
use tera::{Context as TeraContext, Tera};
|
||||
|
||||
|
@ -35,7 +35,7 @@ pub struct Page {
|
|||
/// The front matter meta-data
|
||||
pub meta: PageFrontMatter,
|
||||
/// The list of parent sections
|
||||
pub ancestors: Vec<Key>,
|
||||
pub ancestors: Vec<DefaultKey>,
|
||||
/// The actual content of the page, in markdown
|
||||
pub raw_content: String,
|
||||
/// All the non-md files we found next to the .md file
|
||||
|
@ -58,13 +58,13 @@ pub struct Page {
|
|||
/// as summary
|
||||
pub summary: Option<String>,
|
||||
/// The earlier page, for pages sorted by date
|
||||
pub earlier: Option<Key>,
|
||||
pub earlier: Option<DefaultKey>,
|
||||
/// The later page, for pages sorted by date
|
||||
pub later: Option<Key>,
|
||||
pub later: Option<DefaultKey>,
|
||||
/// The lighter page, for pages sorted by weight
|
||||
pub lighter: Option<Key>,
|
||||
pub lighter: Option<DefaultKey>,
|
||||
/// The heavier page, for pages sorted by weight
|
||||
pub heavier: Option<Key>,
|
||||
pub heavier: Option<DefaultKey>,
|
||||
/// Toc made from the headings of the markdown file
|
||||
pub toc: Vec<Heading>,
|
||||
/// How many words in the raw content
|
||||
|
@ -76,7 +76,7 @@ pub struct Page {
|
|||
/// Corresponds to the lang in the {slug}.{lang}.md file scheme
|
||||
pub lang: String,
|
||||
/// Contains all the translated version of that page
|
||||
pub translations: Vec<Key>,
|
||||
pub translations: Vec<DefaultKey>,
|
||||
/// Contains the internal links that have an anchor: we can only check the anchor
|
||||
/// after all pages have been built and their ToC compiled. The page itself should exist otherwise
|
||||
/// it would have errored before getting there
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use slotmap::Key;
|
||||
use slotmap::DefaultKey;
|
||||
use tera::{Context as TeraContext, Tera};
|
||||
|
||||
use config::Config;
|
||||
|
@ -38,13 +38,13 @@ pub struct Section {
|
|||
/// All the non-md files we found next to the .md file as string for use in templates
|
||||
pub serialized_assets: Vec<String>,
|
||||
/// All direct pages of that section
|
||||
pub pages: Vec<Key>,
|
||||
pub pages: Vec<DefaultKey>,
|
||||
/// All pages that cannot be sorted in this section
|
||||
pub ignored_pages: Vec<Key>,
|
||||
pub ignored_pages: Vec<DefaultKey>,
|
||||
/// The list of parent sections
|
||||
pub ancestors: Vec<Key>,
|
||||
pub ancestors: Vec<DefaultKey>,
|
||||
/// All direct subsections
|
||||
pub subsections: Vec<Key>,
|
||||
pub subsections: Vec<DefaultKey>,
|
||||
/// Toc made from the headings of the markdown file
|
||||
pub toc: Vec<Heading>,
|
||||
/// How many words in the raw content
|
||||
|
@ -56,7 +56,7 @@ pub struct Section {
|
|||
/// Corresponds to the lang in the _index.{lang}.md file scheme
|
||||
pub lang: String,
|
||||
/// Contains all the translated version of that section
|
||||
pub translations: Vec<Key>,
|
||||
pub translations: Vec<DefaultKey>,
|
||||
/// Contains the internal links that have an anchor: we can only check the anchor
|
||||
/// after all pages have been built and their ToC compiled. The page itself should exist otherwise
|
||||
/// it would have errored before getting there
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use slotmap::{DenseSlotMap, Key};
|
||||
use slotmap::{DenseSlotMap, DefaultKey};
|
||||
|
||||
use front_matter::SortBy;
|
||||
|
||||
|
@ -19,13 +19,13 @@ use sorting::{find_siblings, sort_pages_by_date, sort_pages_by_weight};
|
|||
#[derive(Debug)]
|
||||
pub struct Library {
|
||||
/// All the pages of the site
|
||||
pages: DenseSlotMap<Page>,
|
||||
pages: DenseSlotMap<DefaultKey, Page>,
|
||||
/// All the sections of the site
|
||||
sections: DenseSlotMap<Section>,
|
||||
sections: DenseSlotMap<DefaultKey, Section>,
|
||||
/// A mapping path -> key for pages so we can easily get their key
|
||||
pub paths_to_pages: HashMap<PathBuf, Key>,
|
||||
pub paths_to_pages: HashMap<PathBuf, DefaultKey>,
|
||||
/// A mapping path -> key for sections so we can easily get their key
|
||||
pub paths_to_sections: HashMap<PathBuf, Key>,
|
||||
pub paths_to_sections: HashMap<PathBuf, DefaultKey>,
|
||||
/// Whether we need to look for translations
|
||||
is_multilingual: bool,
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ impl Library {
|
|||
}
|
||||
|
||||
/// Add a section and return its Key
|
||||
pub fn insert_section(&mut self, section: Section) -> Key {
|
||||
pub fn insert_section(&mut self, section: Section) -> DefaultKey {
|
||||
let path = section.file.path.clone();
|
||||
let key = self.sections.insert(section);
|
||||
self.paths_to_sections.insert(path, key);
|
||||
|
@ -50,18 +50,18 @@ impl Library {
|
|||
}
|
||||
|
||||
/// Add a page and return its Key
|
||||
pub fn insert_page(&mut self, page: Page) -> Key {
|
||||
pub fn insert_page(&mut self, page: Page) -> DefaultKey {
|
||||
let path = page.file.path.clone();
|
||||
let key = self.pages.insert(page);
|
||||
self.paths_to_pages.insert(path, key);
|
||||
key
|
||||
}
|
||||
|
||||
pub fn pages(&self) -> &DenseSlotMap<Page> {
|
||||
pub fn pages(&self) -> &DenseSlotMap<DefaultKey, Page> {
|
||||
&self.pages
|
||||
}
|
||||
|
||||
pub fn pages_mut(&mut self) -> &mut DenseSlotMap<Page> {
|
||||
pub fn pages_mut(&mut self) -> &mut DenseSlotMap<DefaultKey, Page> {
|
||||
&mut self.pages
|
||||
}
|
||||
|
||||
|
@ -69,11 +69,11 @@ impl Library {
|
|||
self.pages.values().collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
pub fn sections(&self) -> &DenseSlotMap<Section> {
|
||||
pub fn sections(&self) -> &DenseSlotMap<DefaultKey, Section> {
|
||||
&self.sections
|
||||
}
|
||||
|
||||
pub fn sections_mut(&mut self) -> &mut DenseSlotMap<Section> {
|
||||
pub fn sections_mut(&mut self) -> &mut DenseSlotMap<DefaultKey, Section> {
|
||||
&mut self.sections
|
||||
}
|
||||
|
||||
|
@ -336,7 +336,7 @@ impl Library {
|
|||
}
|
||||
|
||||
/// Only used in tests
|
||||
pub fn get_section_key<P: AsRef<Path>>(&self, path: P) -> Option<&Key> {
|
||||
pub fn get_section_key<P: AsRef<Path>>(&self, path: P) -> Option<&DefaultKey> {
|
||||
self.paths_to_sections.get(path.as_ref())
|
||||
}
|
||||
|
||||
|
@ -349,15 +349,15 @@ impl Library {
|
|||
.get_mut(self.paths_to_sections.get(path.as_ref()).cloned().unwrap_or_default())
|
||||
}
|
||||
|
||||
pub fn get_section_by_key(&self, key: Key) -> &Section {
|
||||
pub fn get_section_by_key(&self, key: DefaultKey) -> &Section {
|
||||
self.sections.get(key).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_section_mut_by_key(&mut self, key: Key) -> &mut Section {
|
||||
pub fn get_section_mut_by_key(&mut self, key: DefaultKey) -> &mut Section {
|
||||
self.sections.get_mut(key).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_section_path_by_key(&self, key: Key) -> &str {
|
||||
pub fn get_section_path_by_key(&self, key: DefaultKey) -> &str {
|
||||
&self.get_section_by_key(key).file.relative
|
||||
}
|
||||
|
||||
|
@ -365,11 +365,11 @@ impl Library {
|
|||
self.pages.get(self.paths_to_pages.get(path.as_ref()).cloned().unwrap_or_default())
|
||||
}
|
||||
|
||||
pub fn get_page_by_key(&self, key: Key) -> &Page {
|
||||
pub fn get_page_by_key(&self, key: DefaultKey) -> &Page {
|
||||
self.pages.get(key).unwrap()
|
||||
}
|
||||
|
||||
pub fn get_page_mut_by_key(&mut self, key: Key) -> &mut Page {
|
||||
pub fn get_page_mut_by_key(&mut self, key: DefaultKey) -> &mut Page {
|
||||
self.pages.get_mut(key).unwrap()
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use slotmap::Key;
|
||||
use slotmap::DefaultKey;
|
||||
use tera::{to_value, Context, Tera, Value};
|
||||
|
||||
use config::Config;
|
||||
|
@ -44,7 +44,7 @@ impl<'a> Pager<'a> {
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Paginator<'a> {
|
||||
/// All pages in the section/taxonomy
|
||||
all_pages: &'a [Key],
|
||||
all_pages: &'a [DefaultKey],
|
||||
/// Pages split in chunks of `paginate_by`
|
||||
pub pagers: Vec<Pager<'a>>,
|
||||
/// How many content pages on a paginated page at max
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::cmp::Ordering;
|
|||
|
||||
use chrono::NaiveDateTime;
|
||||
use rayon::prelude::*;
|
||||
use slotmap::Key;
|
||||
use slotmap::DefaultKey;
|
||||
|
||||
use content::Page;
|
||||
|
||||
|
@ -21,7 +21,7 @@ pub fn sort_actual_pages_by_date(a: &&Page, b: &&Page) -> Ordering {
|
|||
/// Takes a list of (page key, date, permalink) and sort them by dates if possible
|
||||
/// Pages without date will be put in the unsortable bucket
|
||||
/// The permalink is used to break ties
|
||||
pub fn sort_pages_by_date(pages: Vec<(&Key, Option<NaiveDateTime>, &str)>) -> (Vec<Key>, Vec<Key>) {
|
||||
pub fn sort_pages_by_date(pages: Vec<(&DefaultKey, Option<NaiveDateTime>, &str)>) -> (Vec<DefaultKey>, Vec<DefaultKey>) {
|
||||
let (mut can_be_sorted, cannot_be_sorted): (Vec<_>, Vec<_>) =
|
||||
pages.into_par_iter().partition(|page| page.1.is_some());
|
||||
|
||||
|
@ -40,7 +40,7 @@ pub fn sort_pages_by_date(pages: Vec<(&Key, Option<NaiveDateTime>, &str)>) -> (V
|
|||
/// Takes a list of (page key, weight, permalink) and sort them by weight if possible
|
||||
/// Pages without weight will be put in the unsortable bucket
|
||||
/// The permalink is used to break ties
|
||||
pub fn sort_pages_by_weight(pages: Vec<(&Key, Option<usize>, &str)>) -> (Vec<Key>, Vec<Key>) {
|
||||
pub fn sort_pages_by_weight(pages: Vec<(&DefaultKey, Option<usize>, &str)>) -> (Vec<DefaultKey>, Vec<DefaultKey>) {
|
||||
let (mut can_be_sorted, cannot_be_sorted): (Vec<_>, Vec<_>) =
|
||||
pages.into_par_iter().partition(|page| page.1.is_some());
|
||||
|
||||
|
@ -57,7 +57,7 @@ pub fn sort_pages_by_weight(pages: Vec<(&Key, Option<usize>, &str)>) -> (Vec<Key
|
|||
}
|
||||
|
||||
/// Find the lighter/heavier and earlier/later pages for all pages having a date/weight
|
||||
pub fn find_siblings(sorted: &[Key]) -> Vec<(Key, Option<Key>, Option<Key>)> {
|
||||
pub fn find_siblings(sorted: &[DefaultKey]) -> Vec<(DefaultKey, Option<DefaultKey>, Option<DefaultKey>)> {
|
||||
let mut res = Vec::with_capacity(sorted.len());
|
||||
let length = sorted.len();
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use slotmap::Key;
|
||||
use slotmap::DefaultKey;
|
||||
use slug::slugify;
|
||||
use tera::{Context, Tera};
|
||||
|
||||
|
@ -44,7 +44,7 @@ pub struct TaxonomyItem {
|
|||
pub name: String,
|
||||
pub slug: String,
|
||||
pub permalink: String,
|
||||
pub pages: Vec<Key>,
|
||||
pub pages: Vec<DefaultKey>,
|
||||
}
|
||||
|
||||
impl TaxonomyItem {
|
||||
|
@ -52,7 +52,7 @@ impl TaxonomyItem {
|
|||
name: &str,
|
||||
taxonomy: &TaxonomyConfig,
|
||||
config: &Config,
|
||||
keys: Vec<Key>,
|
||||
keys: Vec<DefaultKey>,
|
||||
library: &Library,
|
||||
) -> Self {
|
||||
// Taxonomy are almost always used for blogs so we filter by dates
|
||||
|
@ -113,7 +113,7 @@ impl Taxonomy {
|
|||
fn new(
|
||||
kind: TaxonomyConfig,
|
||||
config: &Config,
|
||||
items: HashMap<String, Vec<Key>>,
|
||||
items: HashMap<String, Vec<DefaultKey>>,
|
||||
library: &Library,
|
||||
) -> Taxonomy {
|
||||
let mut sorted_items = vec![];
|
||||
|
|
Loading…
Reference in a new issue