Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add resources and collapse single-crate projects #36

Merged
merged 2 commits into from Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
492 changes: 421 additions & 71 deletions ecosystem.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/cli.rs
Expand Up @@ -12,7 +12,7 @@ pub enum Commands {
/// Add a project to the ecosystem file
Add {
#[clap(flatten)]
project: crate::ecosystem::Project,
project: crate::ecosystem::ProjectSrc,
},
/// Build the site.
Build {
Expand Down
48 changes: 43 additions & 5 deletions src/ecosystem.rs
Expand Up @@ -7,7 +7,7 @@ use toml_edit::{Array, Document, Formatted, Item, Table, Value};
struct EcosystemSrc {
topics: HashMap<String, TopicSrc>,
#[serde(rename = "project")]
projects: Vec<Project>,
projects: Vec<ProjectSrc>,
showcase: Vec<ShowcaseExhibit>,
}

Expand All @@ -17,8 +17,8 @@ pub struct Ecosystem {
pub showcase: Vec<ShowcaseExhibit>,
}

#[derive(Args, Clone, Serialize, Deserialize)]
pub struct Project {
#[derive(Args, Clone, Deserialize)]
pub struct ProjectSrc {
/// The name of the project
pub name: String,
/// The description of the project
Expand All @@ -39,6 +39,42 @@ pub struct Project {
pub topics: Vec<String>,
}

#[derive(Debug, Serialize)]
pub struct Project {
pub name: String,
pub description: Option<String>,
pub repo: Option<String>,
// we have both so that if there's only one, we can collapse it
pub only_crate: Option<String>,
pub crates: Option<Vec<String>>,
pub docs: Option<String>,
pub topics: Vec<String>,
}

impl From<ProjectSrc> for Project {
fn from(src: ProjectSrc) -> Self {
let (only_crate, crates) = if let Some(crates) = src.crates {
if crates.len() == 1 {
(Some(crates[0].clone()), None)
} else {
(None, Some(crates))
}
} else {
(None, None)
};

Self {
name: src.name,
description: src.description,
repo: src.repo,
only_crate,
crates,
docs: src.docs,
topics: src.topics,
}
}
}

#[derive(Deserialize)]
struct TopicSrc {
name: String,
Expand Down Expand Up @@ -74,14 +110,16 @@ pub fn parse(source: &str) -> Result<Ecosystem, Box<dyn Error>> {
.collect();
topics.sort_by(|a, b| a.id.to_lowercase().cmp(&b.id.to_lowercase()));

let projects = parsed_data.projects.into_iter().map(Into::into).collect();

Ok(Ecosystem {
projects: parsed_data.projects,
projects,
topics,
showcase: parsed_data.showcase,
})
}

pub fn add_project(source: &str, project: &Project) -> Result<String, Box<dyn Error>> {
pub fn add_project(source: &str, project: &ProjectSrc) -> Result<String, Box<dyn Error>> {
let mut doc = fs::read_to_string(source)?.parse::<Document>()?;

macro_rules! value_str {
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Expand Up @@ -25,7 +25,7 @@ fn main() {
}
}

fn add_project(project: ecosystem::Project) {
fn add_project(project: ecosystem::ProjectSrc) {
let toml = ecosystem::add_project(ECOSYSTEM_SOURCE_FILE, &project).unwrap();
fs::write(ECOSYSTEM_SOURCE_FILE, toml).unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion src/templates.rs
Expand Up @@ -42,7 +42,7 @@ impl Function for UrlFor {
None => return Err("required argument `name` not provided".into()),
};

Ok(to_value(&self.resolve_url(&section, &name)?)?)
Ok(to_value(self.resolve_url(&section, &name)?)?)
}

fn is_safe(&self) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Expand Up @@ -5,7 +5,7 @@ use std::{
};

pub fn copy_dir_all(src: &Path, dst: &Path) -> Result<()> {
create_dir_all(&dst)?;
create_dir_all(dst)?;
for entry in read_dir(src)? {
let entry = entry?;
if entry.file_type()?.is_dir() {
Expand Down
4 changes: 3 additions & 1 deletion templates/index.tera.html
Expand Up @@ -8,7 +8,9 @@ <h1>Are we lang yet?</h1>
<h1 class="tagline">There and thriving.</h1>

<p>
blah blah blah
Rust's expressiveness and performance makes writing languages and tooling
enjoyable and practical. It has an established and growing ecosystem of
crates for all purposes, including lexing, parsing, and code generation.
</p>

<h2>Can I write a compiler in Rust?</h2>
Expand Down
4 changes: 4 additions & 0 deletions templates/topic.tera.html
Expand Up @@ -16,6 +16,10 @@ <h2>
{% if project.repo %}
<a title="repository" href="{{ project.repo }}"><img class="icon" src="/assets/icons/code.svg" alt="repository"></img></a>
{% endif %}
{% if project.only_crate %}
<a title="crates.io link" href="https://crates.io/crates/{{ project.only_crate }}"><img class="icon" src="/assets/icons/repo.svg" alt="crates.io link"></img></a>
<a title="docs.rs link" href="https://docs.rs/{{ project.only_crate }}"><img class="icon" src="/assets/icons/book.svg" alt="docs.rs link"></img></a>
{% endif %}
</h2>

{% if project.description %}
Expand Down