Remove crates-index's documentation field, rename crates-index.js to index.js

This commit is contained in:
Folyd 2020-02-07 12:04:39 +08:00
parent 3c390cb8bc
commit 986ac2c7b5
5 changed files with 5 additions and 6 deletions

View file

@ -63,7 +63,7 @@ async function checkLatestCratesIndex() {
async function loadLatestCratesIndex(version) {
return new Promise((resolve, reject) => {
let script = document.createElement('script');
script.src = `${CRATES_INDEX_BASE_URL}/crates-index.js?${version}`;
script.src = `${CRATES_INDEX_BASE_URL}/index.js?${version}`;
script.onload = resolve;
script.onerror = reject;
document.body.appendChild(script);

View file

@ -42,4 +42,4 @@ local manifest = {
if std.extVar("browser") == "firefox" then
manifest
else
manifest.appendContentSecurityPolicy(" script-src-elem 'self' https://rust-search-extension.now.sh/crates/crates-index.js;")
manifest.appendContentSecurityPolicy(" script-src-elem 'self' https://rust-search-extension.now.sh/crates/index.js;")

View file

@ -36,7 +36,6 @@ struct Crate {
id: String,
#[serde(deserialize_with = "deserialize_crate_description")]
description: Option<String>,
documentation: Option<String>,
max_version: Option<String>,
}
@ -70,14 +69,13 @@ async fn generate_javascript_crates_index(
minifier: &Minifier,
) -> std::io::Result<String> {
let mut contents = String::from("var N=null;");
let crates_map: HashMap<String, [Option<String>; 3]> = crates
let crates_map: HashMap<String, [Option<String>; 2]> = crates
.into_iter()
.map(|item| {
(
item.id.to_lowercase(),
[
item.description.map(|value| minifier.mapping_minify(value)),
item.documentation.map(Minifier::minify_url),
item.max_version,
],
)

View file

@ -78,6 +78,7 @@ impl Minifier {
.collect()
}
#[allow(unused)]
pub fn minify_url(url: String) -> String {
url.to_lowercase()
.replace("http://", "")

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e
CRATES_INDEX_PATH="/tmp/crates-index.js"
CRATES_INDEX_PATH="/tmp/index.js"
BRANCH="now"
build() {