Compare commits
17 commits
Author | SHA1 | Date | |
---|---|---|---|
f1ed826eee | |||
f1e5388db1 | |||
ba4086bac9 | |||
067dae1356 | |||
0c8d70d6e1 | |||
e8bb51d388 | |||
b38eabb27b | |||
1e7718865c | |||
44fc06cd4b | |||
f700b484be | |||
0cec19e682 | |||
3be7f2795f | |||
97a8e9a2ba | |||
63738518a3 | |||
3dfdc4c44e | |||
a30cb5087b | |||
d76e7a49ed |
22 changed files with 718 additions and 569 deletions
|
@ -18,4 +18,5 @@ repos:
|
||||||
name: ui/menu lint+fmt
|
name: ui/menu lint+fmt
|
||||||
language: system
|
language: system
|
||||||
files: ^ui/menu/
|
files: ^ui/menu/
|
||||||
entry: sh -c "npm run --prefix ui/menu pc"
|
pass_filenames: false
|
||||||
|
entry: npm run --prefix ui/menu pc
|
||||||
|
|
35
CHANGELOG.md
35
CHANGELOG.md
|
@ -2,6 +2,41 @@
|
||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [0.4.2] - 2023-07-22
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- Container entrypoint
|
||||||
|
- Website version ordering
|
||||||
|
|
||||||
|
### Miscellaneous Tasks
|
||||||
|
|
||||||
|
- Fix npm pre-commit hook
|
||||||
|
|
||||||
|
## [0.4.1] - 2023-04-05
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
- Stop propagation of key events on menu search
|
||||||
|
- Use sh
|
||||||
|
- Remove version prefix from "latest" tag
|
||||||
|
- Detect CI commit SHA
|
||||||
|
- Use better abbreviations for page names
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- Add upload script
|
||||||
|
|
||||||
|
## [0.4.0] - 2023-04-02
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- [**breaking**] Switch database format to CBOR (not compatible with previous format)
|
||||||
|
|
||||||
|
### Miscellaneous Tasks
|
||||||
|
|
||||||
|
- Hide version-bump messages
|
||||||
|
|
||||||
## [0.3.0] - 2023-04-02
|
## [0.3.0] - 2023-04-02
|
||||||
|
|
||||||
### Bug Fixes
|
### Bug Fixes
|
||||||
|
|
1012
Cargo.lock
generated
1012
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "talon"
|
name = "talon"
|
||||||
version = "0.3.0"
|
version = "0.4.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["ThetaDev <t.testboy@gmail.com>"]
|
authors = ["ThetaDev <t.testboy@gmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -16,7 +16,7 @@ tokio = { version = "1.25.0", features = ["rt-multi-thread", "fs", "signal"] }
|
||||||
sled = "0.34.7"
|
sled = "0.34.7"
|
||||||
serde = "1.0.152"
|
serde = "1.0.152"
|
||||||
serde_json = "1.0.93"
|
serde_json = "1.0.93"
|
||||||
rmp-serde = "1.1.1"
|
serde_cbor = "0.11.2"
|
||||||
toml = "0.7.2"
|
toml = "0.7.2"
|
||||||
thiserror = "1.0.38"
|
thiserror = "1.0.38"
|
||||||
time = { version = "0.3.15", features = [
|
time = { version = "0.3.15", features = [
|
||||||
|
|
|
@ -48,7 +48,7 @@ commit_parsers = [
|
||||||
{ message = "^refactor", group = "Refactor"},
|
{ message = "^refactor", group = "Refactor"},
|
||||||
{ message = "^style", group = "Styling"},
|
{ message = "^style", group = "Styling"},
|
||||||
{ message = "^test", group = "Testing"},
|
{ message = "^test", group = "Testing"},
|
||||||
{ message = "^chore\\(release\\): prepare for", skip = true},
|
{ message = "^chore\\(release\\):", skip = true},
|
||||||
{ message = "(^chore)|(^ci)", group = "Miscellaneous Tasks"},
|
{ message = "(^chore)|(^ci)", group = "Miscellaneous Tasks"},
|
||||||
{ body = ".*security", group = "Security"},
|
{ body = ".*security", group = "Security"},
|
||||||
]
|
]
|
||||||
|
|
|
@ -41,7 +41,8 @@ for arch in "${ARCHITECTURES[@]}"; do
|
||||||
|
|
||||||
# Finalize container
|
# Finalize container
|
||||||
buildah umount "$container"
|
buildah umount "$container"
|
||||||
buildah config --entrypoint "/talon" --cmd "run -d /data" --arch "$arch" --port 3000 --author "ThetaDev" "$container"
|
# entrypoint syntax: see issue https://github.com/containers/buildah/issues/1768
|
||||||
|
buildah config --entrypoint '["/talon"]' --cmd "run -d /data" --arch "$arch" --port 3000 --author "ThetaDev" "$container"
|
||||||
buildah commit "$container" "$IMAGE:$arch-$TAG"
|
buildah commit "$container" "$IMAGE:$arch-$TAG"
|
||||||
|
|
||||||
buildah manifest add "$REGISTRY/$IMAGE:$TAG" "$IMAGE:$arch-$TAG"
|
buildah manifest add "$REGISTRY/$IMAGE:$TAG" "$IMAGE:$arch-$TAG"
|
||||||
|
|
75
scripts/upload.sh
Executable file
75
scripts/upload.sh
Executable file
|
@ -0,0 +1,75 @@
|
||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
# Check for dependencies
|
||||||
|
which curl > /dev/null
|
||||||
|
which jq > /dev/null
|
||||||
|
|
||||||
|
# Assert required variables
|
||||||
|
if [ -z "$TALON_KEY" ]; then echo "TALON_KEY unset"; exit 1; fi
|
||||||
|
if [ -z "$TALON_URL" ]; then echo "TALON_URL unset"; exit 1; fi
|
||||||
|
if [ -z "$SUBDOMAIN" ]; then echo "SUBDOMAIN unset"; exit 1; fi
|
||||||
|
|
||||||
|
API_URL="$TALON_URL/api"
|
||||||
|
API_KEY_H="x-api-key: $TALON_KEY"
|
||||||
|
|
||||||
|
# Check if the website already exists
|
||||||
|
WEBSITE_STATUS=$(curl --head -o /dev/null -s -w "%{http_code}" "$API_URL/website/$SUBDOMAIN")
|
||||||
|
if [ "$WEBSITE_STATUS" = "200" ]; then
|
||||||
|
echo "Website '$SUBDOMAIN' found"
|
||||||
|
else
|
||||||
|
# Create the website if it does not exist
|
||||||
|
if [ -z "$WEBSITE_NAME" ]; then echo "WEBSITE_NAME unset"; exit 1; fi
|
||||||
|
|
||||||
|
CREATE_BODY=$(jq -c --null-input --arg name "$WEBSITE_NAME" --arg color "$WEBSITE_COLOR" \
|
||||||
|
--arg visibility "$WEBSITE_VISIBILITY" --arg source_url "$WEBSITE_SOURCE_URL" \
|
||||||
|
--arg source_icon "$WEBSITE_SOURCE_ICON" \
|
||||||
|
'{"name": $name, "color": $color, "visibility": $visibility, "source_url": $source_url, "source_icon": $source_icon} | delpaths([path(.[]| select(.==""))])')
|
||||||
|
echo "Creating website '$SUBDOMAIN': $CREATE_BODY"
|
||||||
|
|
||||||
|
curl -Ss --fail -X "PUT" -H "$API_KEY_H" -H "content-type: application/json" --data "$CREATE_BODY" "$API_URL/website/$SUBDOMAIN"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check the upload directory
|
||||||
|
if [ ! -d "$1" ]; then echo "Upload directory does not exist"; exit 1; fi
|
||||||
|
if [ ! -f "$1/index.html" ]; then echo "Upload directory does not contain index.html"; exit 1; fi
|
||||||
|
|
||||||
|
# Validate fallback page param
|
||||||
|
if [ "$FALLBACK" ] && [ ! -f "$1/$FALLBACK" ]; then echo "fallback page $FALLBACK does not exist"; exit 1; fi
|
||||||
|
|
||||||
|
# Automatically detect fallback pages
|
||||||
|
if [ -z "$SPA" ] && [ -z "$FALLBACK" ]; then
|
||||||
|
if [ -f "$1/404.html" ]; then FALLBACK="404.html"; fi
|
||||||
|
if [ -f "$1/200.html" ]; then SPA=true; FALLBACK="200.html"; fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
push_arg() {
|
||||||
|
if [ "$UPLOAD_ARGS" ]; then UPLOAD_ARGS="$UPLOAD_ARGS&"; fi
|
||||||
|
UPLOAD_ARGS="$UPLOAD_ARGS$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$FALLBACK" ]; then push_arg "fallback=$FALLBACK"; fi
|
||||||
|
if [ "$SPA" = "true" ]; then push_arg "spa=true"; fi
|
||||||
|
|
||||||
|
if [ "$UPLOAD_ARGS" ]; then UPLOAD_ARGS="?$UPLOAD_ARGS"; fi
|
||||||
|
|
||||||
|
if [ "$CI_COMMIT_SHA" ]; then
|
||||||
|
echo "Git commit: $CI_COMMIT_SHA"
|
||||||
|
push_arg "commit=$CI_COMMIT_SHA"
|
||||||
|
elif GIT_COMMIT=$(git rev-parse HEAD 2> /dev/null); then
|
||||||
|
echo "Git commit: $GIT_COMMIT"
|
||||||
|
push_arg "commit=$GIT_COMMIT"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Compress website
|
||||||
|
ARCHIVE=$(mktemp)
|
||||||
|
tar -cz --directory "$1" --file "$ARCHIVE" .
|
||||||
|
|
||||||
|
# Upload website
|
||||||
|
echo "Version params: $UPLOAD_ARGS"
|
||||||
|
echo "Uploading..."
|
||||||
|
curl --fail -X "POST" -H "$API_KEY_H" -H "content-type: application/octet-stream" --data-binary "@$ARCHIVE" "$API_URL/website/$SUBDOMAIN/upload$UPLOAD_ARGS"
|
||||||
|
|
||||||
|
rm "$ARCHIVE"
|
||||||
|
|
||||||
|
echo "Website uploaded ;-)"
|
19
src/api.rs
19
src/api.rs
|
@ -107,7 +107,7 @@ impl TalonApi {
|
||||||
.db
|
.db
|
||||||
.get_website(&subdomain)
|
.get_website(&subdomain)
|
||||||
.map(|website| {
|
.map(|website| {
|
||||||
let modified = website.updated_at();
|
let modified = website.updated_at;
|
||||||
Response::new(Json(Website::from((subdomain.0, website)))).header(
|
Response::new(Json(Website::from((subdomain.0, website)))).header(
|
||||||
header::LAST_MODIFIED,
|
header::LAST_MODIFIED,
|
||||||
httpdate::fmt_http_date(modified.into()),
|
httpdate::fmt_http_date(modified.into()),
|
||||||
|
@ -300,18 +300,17 @@ impl TalonApi {
|
||||||
subdomain: Path<String>,
|
subdomain: Path<String>,
|
||||||
) -> Result<Response<Json<Vec<Version>>>> {
|
) -> Result<Response<Json<Vec<Version>>>> {
|
||||||
let website = talon.db.get_website(&subdomain)?;
|
let website = talon.db.get_website(&subdomain)?;
|
||||||
talon
|
let mut versions = talon
|
||||||
.db
|
.db
|
||||||
.get_website_versions(&subdomain)
|
.get_website_versions(&subdomain)
|
||||||
.map(|r| r.map(Version::from))
|
.map(|r| r.map(Version::from))
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
.map(|data| {
|
versions.sort_by_key(|v| v.id);
|
||||||
Response::new(Json(data)).header(
|
|
||||||
header::LAST_MODIFIED,
|
Ok(Response::new(Json(versions)).header(
|
||||||
httpdate::fmt_http_date(website.updated_at().into()),
|
header::LAST_MODIFIED,
|
||||||
)
|
httpdate::fmt_http_date(website.updated_at.into()),
|
||||||
})
|
))
|
||||||
.map_err(Error::from)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get version
|
/// Get version
|
||||||
|
|
|
@ -30,10 +30,8 @@ struct DbInner {
|
||||||
pub enum DbError {
|
pub enum DbError {
|
||||||
#[error("sled db error: {0}")]
|
#[error("sled db error: {0}")]
|
||||||
Sled(#[from] sled::Error),
|
Sled(#[from] sled::Error),
|
||||||
#[error("msgpack serialization error: {0}")]
|
#[error("cbor serialization error: {0}")]
|
||||||
Serialize(#[from] rmp_serde::encode::Error),
|
Serialize(#[from] serde_cbor::Error),
|
||||||
#[error("msgpack deserialization error: {0}")]
|
|
||||||
Deserialize(#[from] rmp_serde::decode::Error),
|
|
||||||
#[error("json serialization error: {0}")]
|
#[error("json serialization error: {0}")]
|
||||||
Json(#[from] serde_json::Error),
|
Json(#[from] serde_json::Error),
|
||||||
#[error("{0} with id `{1}` already exists")]
|
#[error("{0} with id `{1}` already exists")]
|
||||||
|
@ -100,7 +98,7 @@ impl Db {
|
||||||
for item in self.i.websites.iter() {
|
for item in self.i.websites.iter() {
|
||||||
let (k, v) = item?;
|
let (k, v) = item?;
|
||||||
let key = Self::key_to_string(k.to_vec())?;
|
let key = Self::key_to_string(k.to_vec())?;
|
||||||
let value = rmp_serde::from_slice::<Website>(&v)?;
|
let value = serde_cbor::from_slice::<Website>(&v)?;
|
||||||
|
|
||||||
let dataset = ExportDataset::Website { key, value };
|
let dataset = ExportDataset::Website { key, value };
|
||||||
|
|
||||||
|
@ -111,7 +109,7 @@ impl Db {
|
||||||
for item in self.i.versions.iter() {
|
for item in self.i.versions.iter() {
|
||||||
let (k, v) = item?;
|
let (k, v) = item?;
|
||||||
let key = Self::key_to_string(k.to_vec())?;
|
let key = Self::key_to_string(k.to_vec())?;
|
||||||
let value = rmp_serde::from_slice::<Version>(&v)?;
|
let value = serde_cbor::from_slice::<Version>(&v)?;
|
||||||
|
|
||||||
let dataset = ExportDataset::Version { key, value };
|
let dataset = ExportDataset::Version { key, value };
|
||||||
serde_json::to_writer(&mut writer, &dataset)?;
|
serde_json::to_writer(&mut writer, &dataset)?;
|
||||||
|
@ -152,11 +150,11 @@ impl Db {
|
||||||
fn import_dataset(&self, ds: ExportDataset) -> Result<()> {
|
fn import_dataset(&self, ds: ExportDataset) -> Result<()> {
|
||||||
match ds {
|
match ds {
|
||||||
ExportDataset::Website { key, value } => {
|
ExportDataset::Website { key, value } => {
|
||||||
let data = rmp_serde::to_vec(&value)?;
|
let data = serde_cbor::to_vec(&value)?;
|
||||||
self.i.websites.insert(key, data)?;
|
self.i.websites.insert(key, data)?;
|
||||||
}
|
}
|
||||||
ExportDataset::Version { key, value } => {
|
ExportDataset::Version { key, value } => {
|
||||||
let data = rmp_serde::to_vec(&value)?;
|
let data = serde_cbor::to_vec(&value)?;
|
||||||
self.i.versions.insert(key, data)?;
|
self.i.versions.insert(key, data)?;
|
||||||
}
|
}
|
||||||
ExportDataset::File { key, value } => {
|
ExportDataset::File { key, value } => {
|
||||||
|
@ -178,13 +176,13 @@ impl Db {
|
||||||
/// Get a website from the database
|
/// Get a website from the database
|
||||||
pub fn get_website(&self, subdomain: &str) -> Result<Website> {
|
pub fn get_website(&self, subdomain: &str) -> Result<Website> {
|
||||||
let data = self.i.websites.get(subdomain)?;
|
let data = self.i.websites.get(subdomain)?;
|
||||||
data.and_then(|data| rmp_serde::from_slice::<Website>(data.as_ref()).ok())
|
data.and_then(|data| serde_cbor::from_slice::<Website>(data.as_ref()).ok())
|
||||||
.ok_or_else(|| DbError::NotExists("website", subdomain.to_owned()))
|
.ok_or_else(|| DbError::NotExists("website", subdomain.to_owned()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert a new website into the database
|
/// Insert a new website into the database
|
||||||
pub fn insert_website(&self, subdomain: &str, website: &Website) -> Result<()> {
|
pub fn insert_website(&self, subdomain: &str, website: &Website) -> Result<()> {
|
||||||
let data = rmp_serde::to_vec(website)?;
|
let data = serde_cbor::to_vec(website)?;
|
||||||
self.i
|
self.i
|
||||||
.websites
|
.websites
|
||||||
.compare_and_swap(subdomain, None::<&[u8]>, Some(data))?
|
.compare_and_swap(subdomain, None::<&[u8]>, Some(data))?
|
||||||
|
@ -198,7 +196,7 @@ impl Db {
|
||||||
.i
|
.i
|
||||||
.websites
|
.websites
|
||||||
.update_and_fetch(subdomain, |data| match data {
|
.update_and_fetch(subdomain, |data| match data {
|
||||||
Some(data) => match rmp_serde::from_slice::<Website>(data) {
|
Some(data) => match serde_cbor::from_slice::<Website>(data) {
|
||||||
Ok(mut w) => {
|
Ok(mut w) => {
|
||||||
let website = website.clone();
|
let website = website.clone();
|
||||||
w.name = website.name.unwrap_or(w.name);
|
w.name = website.name.unwrap_or(w.name);
|
||||||
|
@ -208,9 +206,9 @@ impl Db {
|
||||||
w.source_url = website.source_url.unwrap_or(w.source_url);
|
w.source_url = website.source_url.unwrap_or(w.source_url);
|
||||||
w.source_icon = website.source_icon.unwrap_or(w.source_icon);
|
w.source_icon = website.source_icon.unwrap_or(w.source_icon);
|
||||||
w.has_icon = website.has_icon.unwrap_or(w.has_icon);
|
w.has_icon = website.has_icon.unwrap_or(w.has_icon);
|
||||||
w.updated_at = Some(OffsetDateTime::now_utc());
|
w.updated_at = OffsetDateTime::now_utc();
|
||||||
|
|
||||||
rmp_serde::to_vec(&w).ok()
|
serde_cbor::to_vec(&w).ok()
|
||||||
}
|
}
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
},
|
},
|
||||||
|
@ -252,7 +250,7 @@ impl Db {
|
||||||
self.i.websites.iter().map(|r| {
|
self.i.websites.iter().map(|r| {
|
||||||
r.map_err(DbError::from).and_then(|(k, v)| {
|
r.map_err(DbError::from).and_then(|(k, v)| {
|
||||||
let subdomain = Self::key_to_string(k.to_vec())?;
|
let subdomain = Self::key_to_string(k.to_vec())?;
|
||||||
let website = rmp_serde::from_slice::<Website>(&v)?;
|
let website = serde_cbor::from_slice::<Website>(&v)?;
|
||||||
Ok((subdomain, website))
|
Ok((subdomain, website))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -301,7 +299,7 @@ impl Db {
|
||||||
let key = Self::version_key(subdomain, id);
|
let key = Self::version_key(subdomain, id);
|
||||||
|
|
||||||
let data = self.i.versions.get(&key)?;
|
let data = self.i.versions.get(&key)?;
|
||||||
data.and_then(|data| rmp_serde::from_slice::<Version>(data.as_ref()).ok())
|
data.and_then(|data| serde_cbor::from_slice::<Version>(data.as_ref()).ok())
|
||||||
.ok_or_else(|| DbError::NotExists("version", key))
|
.ok_or_else(|| DbError::NotExists("version", key))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,16 +311,16 @@ impl Db {
|
||||||
.i
|
.i
|
||||||
.websites
|
.websites
|
||||||
.update_and_fetch(subdomain, |data| match data {
|
.update_and_fetch(subdomain, |data| match data {
|
||||||
Some(data) => match rmp_serde::from_slice::<Website>(data) {
|
Some(data) => match serde_cbor::from_slice::<Website>(data) {
|
||||||
Ok(mut w) => {
|
Ok(mut w) => {
|
||||||
w.vid_count += 1;
|
w.vid_count += 1;
|
||||||
rmp_serde::to_vec(&w).ok()
|
serde_cbor::to_vec(&w).ok()
|
||||||
}
|
}
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
},
|
},
|
||||||
None => None,
|
None => None,
|
||||||
})?
|
})?
|
||||||
.and_then(|data| rmp_serde::from_slice::<Website>(&data).ok());
|
.and_then(|data| serde_cbor::from_slice::<Website>(&data).ok());
|
||||||
|
|
||||||
let id = match ws {
|
let id = match ws {
|
||||||
Some(ws) => ws.vid_count,
|
Some(ws) => ws.vid_count,
|
||||||
|
@ -330,7 +328,7 @@ impl Db {
|
||||||
};
|
};
|
||||||
|
|
||||||
let key = Self::version_key(subdomain, id);
|
let key = Self::version_key(subdomain, id);
|
||||||
let data = rmp_serde::to_vec(version)?;
|
let data = serde_cbor::to_vec(version)?;
|
||||||
self.i
|
self.i
|
||||||
.versions
|
.versions
|
||||||
.compare_and_swap(&key, None::<&[u8]>, Some(data))?
|
.compare_and_swap(&key, None::<&[u8]>, Some(data))?
|
||||||
|
@ -345,12 +343,12 @@ impl Db {
|
||||||
self.i
|
self.i
|
||||||
.websites
|
.websites
|
||||||
.update_and_fetch(subdomain, |data| match data {
|
.update_and_fetch(subdomain, |data| match data {
|
||||||
Some(data) => match rmp_serde::from_slice::<Website>(data) {
|
Some(data) => match serde_cbor::from_slice::<Website>(data) {
|
||||||
Ok(mut w) => {
|
Ok(mut w) => {
|
||||||
if w.vid_count == version {
|
if w.vid_count == version {
|
||||||
w.vid_count -= 1;
|
w.vid_count -= 1;
|
||||||
}
|
}
|
||||||
rmp_serde::to_vec(&w).ok()
|
serde_cbor::to_vec(&w).ok()
|
||||||
}
|
}
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
},
|
},
|
||||||
|
@ -418,7 +416,7 @@ impl Db {
|
||||||
self.i.versions.scan_prefix(key).map(|r| {
|
self.i.versions.scan_prefix(key).map(|r| {
|
||||||
r.map_err(DbError::from).and_then(|(k, v)| {
|
r.map_err(DbError::from).and_then(|(k, v)| {
|
||||||
let (_, id) = Self::split_version_key(k.to_vec())?;
|
let (_, id) = Self::split_version_key(k.to_vec())?;
|
||||||
let version = rmp_serde::from_slice::<Version>(&v)?;
|
let version = serde_cbor::from_slice::<Version>(&v)?;
|
||||||
Ok((id, version))
|
Ok((id, version))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -12,6 +12,8 @@ pub struct Website {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// Website creation date
|
/// Website creation date
|
||||||
pub created_at: OffsetDateTime,
|
pub created_at: OffsetDateTime,
|
||||||
|
/// Website update date
|
||||||
|
pub updated_at: OffsetDateTime,
|
||||||
/// Latest version ID
|
/// Latest version ID
|
||||||
pub latest_version: Option<u32>,
|
pub latest_version: Option<u32>,
|
||||||
/// Color of the page icon
|
/// Color of the page icon
|
||||||
|
@ -27,11 +29,7 @@ pub struct Website {
|
||||||
/// value + 1 will be the next version ID
|
/// value + 1 will be the next version ID
|
||||||
pub vid_count: u32,
|
pub vid_count: u32,
|
||||||
/// Does the website have an icon?
|
/// Does the website have an icon?
|
||||||
#[serde(default)]
|
|
||||||
pub has_icon: bool,
|
pub has_icon: bool,
|
||||||
/// Website update date
|
|
||||||
#[serde(default)]
|
|
||||||
pub updated_at: Option<OffsetDateTime>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Website {
|
impl Default for Website {
|
||||||
|
@ -41,7 +39,7 @@ impl Default for Website {
|
||||||
Self {
|
Self {
|
||||||
name: Default::default(),
|
name: Default::default(),
|
||||||
created_at,
|
created_at,
|
||||||
updated_at: Some(created_at),
|
updated_at: created_at,
|
||||||
latest_version: Default::default(),
|
latest_version: Default::default(),
|
||||||
color: Default::default(),
|
color: Default::default(),
|
||||||
visibility: Default::default(),
|
visibility: Default::default(),
|
||||||
|
@ -53,12 +51,6 @@ impl Default for Website {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Website {
|
|
||||||
pub fn updated_at(&self) -> OffsetDateTime {
|
|
||||||
self.updated_at.unwrap_or(self.created_at)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Update a website in the database with the contained values
|
/// Update a website in the database with the contained values
|
||||||
///
|
///
|
||||||
/// Values set to `None` remain unchanged.
|
/// Values set to `None` remain unchanged.
|
||||||
|
|
8
tests/fixtures/mod.rs
vendored
8
tests/fixtures/mod.rs
vendored
|
@ -75,7 +75,7 @@ fn insert_websites(db: &Db) {
|
||||||
&Website {
|
&Website {
|
||||||
name: "ThetaDev".to_owned(),
|
name: "ThetaDev".to_owned(),
|
||||||
created_at: datetime!(2023-02-18 16:30 +0),
|
created_at: datetime!(2023-02-18 16:30 +0),
|
||||||
updated_at: Some(datetime!(2023-02-18 16:30 +0)),
|
updated_at: datetime!(2023-02-18 16:30 +0),
|
||||||
latest_version: Some(2),
|
latest_version: Some(2),
|
||||||
color: Some(2068974),
|
color: Some(2068974),
|
||||||
visibility: talon::model::Visibility::Featured,
|
visibility: talon::model::Visibility::Featured,
|
||||||
|
@ -88,7 +88,7 @@ fn insert_websites(db: &Db) {
|
||||||
&Website {
|
&Website {
|
||||||
name: "Spotify-Gender-Ex".to_owned(),
|
name: "Spotify-Gender-Ex".to_owned(),
|
||||||
created_at: datetime!(2023-02-18 16:30 +0),
|
created_at: datetime!(2023-02-18 16:30 +0),
|
||||||
updated_at: Some(datetime!(2023-02-18 16:30 +0)),
|
updated_at: datetime!(2023-02-18 16:30 +0),
|
||||||
latest_version: Some(1),
|
latest_version: Some(1),
|
||||||
color: Some(1947988),
|
color: Some(1947988),
|
||||||
visibility: talon::model::Visibility::Featured,
|
visibility: talon::model::Visibility::Featured,
|
||||||
|
@ -103,7 +103,7 @@ fn insert_websites(db: &Db) {
|
||||||
&Website {
|
&Website {
|
||||||
name: "RustyPipe".to_owned(),
|
name: "RustyPipe".to_owned(),
|
||||||
created_at: datetime!(2023-02-20 18:30 +0),
|
created_at: datetime!(2023-02-20 18:30 +0),
|
||||||
updated_at: Some(datetime!(2023-02-20 18:30 +0)),
|
updated_at: datetime!(2023-02-20 18:30 +0),
|
||||||
latest_version: Some(1),
|
latest_version: Some(1),
|
||||||
color: Some(7943647),
|
color: Some(7943647),
|
||||||
visibility: talon::model::Visibility::Featured,
|
visibility: talon::model::Visibility::Featured,
|
||||||
|
@ -118,7 +118,7 @@ fn insert_websites(db: &Db) {
|
||||||
&Website {
|
&Website {
|
||||||
name: "SvelteKit SPA".to_owned(),
|
name: "SvelteKit SPA".to_owned(),
|
||||||
created_at: datetime!(2023-03-03 22:00 +0),
|
created_at: datetime!(2023-03-03 22:00 +0),
|
||||||
updated_at: Some(datetime!(2023-03-03 22:00 +0)),
|
updated_at: datetime!(2023-03-03 22:00 +0),
|
||||||
latest_version: Some(1),
|
latest_version: Some(1),
|
||||||
color: Some(16727552),
|
color: Some(16727552),
|
||||||
visibility: talon::model::Visibility::Hidden,
|
visibility: talon::model::Visibility::Hidden,
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
source: tests/tests.rs
|
source: tests/tests.rs
|
||||||
expression: data
|
expression: data
|
||||||
---
|
---
|
||||||
{"type":"website","key":"rustypipe","value":{"name":"RustyPipe","created_at":[2023,51,18,30,0,0,0,0,0],"latest_version":1,"color":7943647,"visibility":"featured","source_url":"https://code.thetadev.de/ThetaDev/rustypipe","source_icon":"gitea","vid_count":1,"has_icon":false,"updated_at":[2023,51,18,30,0,0,0,0,0]}}
|
{"type":"website","key":"rustypipe","value":{"name":"RustyPipe","created_at":[2023,51,18,30,0,0,0,0,0],"updated_at":[2023,51,18,30,0,0,0,0,0],"latest_version":1,"color":7943647,"visibility":"featured","source_url":"https://code.thetadev.de/ThetaDev/rustypipe","source_icon":"gitea","vid_count":1,"has_icon":false}}
|
||||||
{"type":"website","key":"spa","value":{"name":"SvelteKit SPA","created_at":[2023,62,22,0,0,0,0,0,0],"latest_version":1,"color":16727552,"visibility":"hidden","source_url":null,"source_icon":null,"vid_count":1,"has_icon":false,"updated_at":[2023,62,22,0,0,0,0,0,0]}}
|
{"type":"website","key":"spa","value":{"name":"SvelteKit SPA","created_at":[2023,62,22,0,0,0,0,0,0],"updated_at":[2023,62,22,0,0,0,0,0,0],"latest_version":1,"color":16727552,"visibility":"hidden","source_url":null,"source_icon":null,"vid_count":1,"has_icon":false}}
|
||||||
{"type":"website","key":"spotify-gender-ex","value":{"name":"Spotify-Gender-Ex","created_at":[2023,49,16,30,0,0,0,0,0],"latest_version":1,"color":1947988,"visibility":"featured","source_url":"https://github.com/Theta-Dev/Spotify-Gender-Ex","source_icon":"github","vid_count":1,"has_icon":false,"updated_at":[2023,49,16,30,0,0,0,0,0]}}
|
{"type":"website","key":"spotify-gender-ex","value":{"name":"Spotify-Gender-Ex","created_at":[2023,49,16,30,0,0,0,0,0],"updated_at":[2023,49,16,30,0,0,0,0,0],"latest_version":1,"color":1947988,"visibility":"featured","source_url":"https://github.com/Theta-Dev/Spotify-Gender-Ex","source_icon":"github","vid_count":1,"has_icon":false}}
|
||||||
{"type":"version","key":"rustypipe:1","value":{"created_at":[2023,51,18,30,0,0,0,0,0],"data":{},"fallback":null,"spa":false}}
|
{"type":"version","key":"rustypipe:1","value":{"created_at":[2023,51,18,30,0,0,0,0,0],"data":{},"fallback":null,"spa":false}}
|
||||||
{"type":"version","key":"spa:1","value":{"created_at":[2023,62,22,0,0,0,0,0,0],"data":{},"fallback":"200.html","spa":true}}
|
{"type":"version","key":"spa:1","value":{"created_at":[2023,62,22,0,0,0,0,0,0],"data":{},"fallback":"200.html","spa":true}}
|
||||||
{"type":"version","key":"spotify-gender-ex:1","value":{"created_at":[2023,49,16,30,0,0,0,0,0],"data":{},"fallback":null,"spa":false}}
|
{"type":"version","key":"spotify-gender-ex:1","value":{"created_at":[2023,49,16,30,0,0,0,0,0],"data":{},"fallback":null,"spa":false}}
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
source: tests/tests.rs
|
source: tests/tests.rs
|
||||||
expression: data
|
expression: data
|
||||||
---
|
---
|
||||||
{"type":"website","key":"-","value":{"name":"ThetaDev","created_at":[2023,49,16,30,0,0,0,0,0],"latest_version":2,"color":2068974,"visibility":"featured","source_url":null,"source_icon":null,"vid_count":2,"has_icon":false,"updated_at":[2023,49,16,30,0,0,0,0,0]}}
|
{"type":"website","key":"-","value":{"name":"ThetaDev","created_at":[2023,49,16,30,0,0,0,0,0],"updated_at":[2023,49,16,30,0,0,0,0,0],"latest_version":2,"color":2068974,"visibility":"featured","source_url":null,"source_icon":null,"vid_count":2,"has_icon":false}}
|
||||||
{"type":"website","key":"rustypipe","value":{"name":"RustyPipe","created_at":[2023,51,18,30,0,0,0,0,0],"latest_version":1,"color":7943647,"visibility":"featured","source_url":"https://code.thetadev.de/ThetaDev/rustypipe","source_icon":"gitea","vid_count":1,"has_icon":false,"updated_at":[2023,51,18,30,0,0,0,0,0]}}
|
{"type":"website","key":"rustypipe","value":{"name":"RustyPipe","created_at":[2023,51,18,30,0,0,0,0,0],"updated_at":[2023,51,18,30,0,0,0,0,0],"latest_version":1,"color":7943647,"visibility":"featured","source_url":"https://code.thetadev.de/ThetaDev/rustypipe","source_icon":"gitea","vid_count":1,"has_icon":false}}
|
||||||
{"type":"website","key":"spa","value":{"name":"SvelteKit SPA","created_at":[2023,62,22,0,0,0,0,0,0],"latest_version":1,"color":16727552,"visibility":"hidden","source_url":null,"source_icon":null,"vid_count":1,"has_icon":false,"updated_at":[2023,62,22,0,0,0,0,0,0]}}
|
{"type":"website","key":"spa","value":{"name":"SvelteKit SPA","created_at":[2023,62,22,0,0,0,0,0,0],"updated_at":[2023,62,22,0,0,0,0,0,0],"latest_version":1,"color":16727552,"visibility":"hidden","source_url":null,"source_icon":null,"vid_count":1,"has_icon":false}}
|
||||||
{"type":"website","key":"spotify-gender-ex","value":{"name":"Spotify-Gender-Ex","created_at":[2023,49,16,30,0,0,0,0,0],"latest_version":1,"color":1947988,"visibility":"featured","source_url":"https://github.com/Theta-Dev/Spotify-Gender-Ex","source_icon":"github","vid_count":1,"has_icon":false,"updated_at":[2023,49,16,30,0,0,0,0,0]}}
|
{"type":"website","key":"spotify-gender-ex","value":{"name":"Spotify-Gender-Ex","created_at":[2023,49,16,30,0,0,0,0,0],"updated_at":[2023,49,16,30,0,0,0,0,0],"latest_version":1,"color":1947988,"visibility":"featured","source_url":"https://github.com/Theta-Dev/Spotify-Gender-Ex","source_icon":"github","vid_count":1,"has_icon":false}}
|
||||||
{"type":"version","key":"-:1","value":{"created_at":[2023,49,16,30,0,0,0,0,0],"data":{"Deployed by":"https://github.com/Theta-Dev/Talon/actions/runs/1352014628","Version":"v0.1.0"},"fallback":null,"spa":false}}
|
{"type":"version","key":"-:1","value":{"created_at":[2023,49,16,30,0,0,0,0,0],"data":{"Deployed by":"https://github.com/Theta-Dev/Talon/actions/runs/1352014628","Version":"v0.1.0"},"fallback":null,"spa":false}}
|
||||||
{"type":"version","key":"-:2","value":{"created_at":[2023,49,16,52,0,0,0,0,0],"data":{"Deployed by":"https://github.com/Theta-Dev/Talon/actions/runs/1354755231","Version":"v0.1.1"},"fallback":null,"spa":false}}
|
{"type":"version","key":"-:2","value":{"created_at":[2023,49,16,52,0,0,0,0,0],"data":{"Deployed by":"https://github.com/Theta-Dev/Talon/actions/runs/1354755231","Version":"v0.1.1"},"fallback":null,"spa":false}}
|
||||||
{"type":"version","key":"rustypipe:1","value":{"created_at":[2023,51,18,30,0,0,0,0,0],"data":{},"fallback":null,"spa":false}}
|
{"type":"version","key":"rustypipe:1","value":{"created_at":[2023,51,18,30,0,0,0,0,0],"data":{},"fallback":null,"spa":false}}
|
||||||
|
|
|
@ -6,6 +6,7 @@ expression: "vec![ws1, ws2, ws3]"
|
||||||
Website(
|
Website(
|
||||||
name: "ThetaDev",
|
name: "ThetaDev",
|
||||||
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
||||||
|
updated_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
||||||
latest_version: Some(2),
|
latest_version: Some(2),
|
||||||
color: Some(2068974),
|
color: Some(2068974),
|
||||||
visibility: featured,
|
visibility: featured,
|
||||||
|
@ -13,11 +14,11 @@ expression: "vec![ws1, ws2, ws3]"
|
||||||
source_icon: None,
|
source_icon: None,
|
||||||
vid_count: 2,
|
vid_count: 2,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
updated_at: Some((2023, 49, 16, 30, 0, 0, 0, 0, 0)),
|
|
||||||
),
|
),
|
||||||
Website(
|
Website(
|
||||||
name: "Spotify-Gender-Ex",
|
name: "Spotify-Gender-Ex",
|
||||||
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
||||||
|
updated_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
||||||
latest_version: Some(1),
|
latest_version: Some(1),
|
||||||
color: Some(1947988),
|
color: Some(1947988),
|
||||||
visibility: featured,
|
visibility: featured,
|
||||||
|
@ -25,11 +26,11 @@ expression: "vec![ws1, ws2, ws3]"
|
||||||
source_icon: Some(github),
|
source_icon: Some(github),
|
||||||
vid_count: 1,
|
vid_count: 1,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
updated_at: Some((2023, 49, 16, 30, 0, 0, 0, 0, 0)),
|
|
||||||
),
|
),
|
||||||
Website(
|
Website(
|
||||||
name: "RustyPipe",
|
name: "RustyPipe",
|
||||||
created_at: (2023, 51, 18, 30, 0, 0, 0, 0, 0),
|
created_at: (2023, 51, 18, 30, 0, 0, 0, 0, 0),
|
||||||
|
updated_at: (2023, 51, 18, 30, 0, 0, 0, 0, 0),
|
||||||
latest_version: Some(1),
|
latest_version: Some(1),
|
||||||
color: Some(7943647),
|
color: Some(7943647),
|
||||||
visibility: featured,
|
visibility: featured,
|
||||||
|
@ -37,6 +38,5 @@ expression: "vec![ws1, ws2, ws3]"
|
||||||
source_icon: Some(gitea),
|
source_icon: Some(gitea),
|
||||||
vid_count: 1,
|
vid_count: 1,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
updated_at: Some((2023, 51, 18, 30, 0, 0, 0, 0, 0)),
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
|
@ -6,6 +6,7 @@ expression: websites
|
||||||
("-", Website(
|
("-", Website(
|
||||||
name: "ThetaDev",
|
name: "ThetaDev",
|
||||||
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
||||||
|
updated_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
||||||
latest_version: Some(2),
|
latest_version: Some(2),
|
||||||
color: Some(2068974),
|
color: Some(2068974),
|
||||||
visibility: featured,
|
visibility: featured,
|
||||||
|
@ -13,11 +14,11 @@ expression: websites
|
||||||
source_icon: None,
|
source_icon: None,
|
||||||
vid_count: 2,
|
vid_count: 2,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
updated_at: Some((2023, 49, 16, 30, 0, 0, 0, 0, 0)),
|
|
||||||
)),
|
)),
|
||||||
("rustypipe", Website(
|
("rustypipe", Website(
|
||||||
name: "RustyPipe",
|
name: "RustyPipe",
|
||||||
created_at: (2023, 51, 18, 30, 0, 0, 0, 0, 0),
|
created_at: (2023, 51, 18, 30, 0, 0, 0, 0, 0),
|
||||||
|
updated_at: (2023, 51, 18, 30, 0, 0, 0, 0, 0),
|
||||||
latest_version: Some(1),
|
latest_version: Some(1),
|
||||||
color: Some(7943647),
|
color: Some(7943647),
|
||||||
visibility: featured,
|
visibility: featured,
|
||||||
|
@ -25,11 +26,11 @@ expression: websites
|
||||||
source_icon: Some(gitea),
|
source_icon: Some(gitea),
|
||||||
vid_count: 1,
|
vid_count: 1,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
updated_at: Some((2023, 51, 18, 30, 0, 0, 0, 0, 0)),
|
|
||||||
)),
|
)),
|
||||||
("spa", Website(
|
("spa", Website(
|
||||||
name: "SvelteKit SPA",
|
name: "SvelteKit SPA",
|
||||||
created_at: (2023, 62, 22, 0, 0, 0, 0, 0, 0),
|
created_at: (2023, 62, 22, 0, 0, 0, 0, 0, 0),
|
||||||
|
updated_at: (2023, 62, 22, 0, 0, 0, 0, 0, 0),
|
||||||
latest_version: Some(1),
|
latest_version: Some(1),
|
||||||
color: Some(16727552),
|
color: Some(16727552),
|
||||||
visibility: hidden,
|
visibility: hidden,
|
||||||
|
@ -37,11 +38,11 @@ expression: websites
|
||||||
source_icon: None,
|
source_icon: None,
|
||||||
vid_count: 1,
|
vid_count: 1,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
updated_at: Some((2023, 62, 22, 0, 0, 0, 0, 0, 0)),
|
|
||||||
)),
|
)),
|
||||||
("spotify-gender-ex", Website(
|
("spotify-gender-ex", Website(
|
||||||
name: "Spotify-Gender-Ex",
|
name: "Spotify-Gender-Ex",
|
||||||
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
||||||
|
updated_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
||||||
latest_version: Some(1),
|
latest_version: Some(1),
|
||||||
color: Some(1947988),
|
color: Some(1947988),
|
||||||
visibility: featured,
|
visibility: featured,
|
||||||
|
@ -49,6 +50,5 @@ expression: websites
|
||||||
source_icon: Some(github),
|
source_icon: Some(github),
|
||||||
vid_count: 1,
|
vid_count: 1,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
updated_at: Some((2023, 49, 16, 30, 0, 0, 0, 0, 0)),
|
|
||||||
)),
|
)),
|
||||||
]
|
]
|
||||||
|
|
|
@ -5,6 +5,7 @@ expression: website
|
||||||
Website(
|
Website(
|
||||||
name: "ThetaDev2",
|
name: "ThetaDev2",
|
||||||
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
||||||
|
updated_at: "[date]",
|
||||||
latest_version: Some(2),
|
latest_version: Some(2),
|
||||||
color: Some(1000),
|
color: Some(1000),
|
||||||
visibility: hidden,
|
visibility: hidden,
|
||||||
|
@ -12,5 +13,4 @@ Website(
|
||||||
source_icon: Some(link),
|
source_icon: Some(link),
|
||||||
vid_count: 2,
|
vid_count: 2,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
updated_at: "[date]",
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -862,6 +862,7 @@ mod api {
|
||||||
Website(
|
Website(
|
||||||
name: "Test",
|
name: "Test",
|
||||||
created_at: "[date]",
|
created_at: "[date]",
|
||||||
|
updated_at: "[date]",
|
||||||
latest_version: None,
|
latest_version: None,
|
||||||
color: Some(1000),
|
color: Some(1000),
|
||||||
visibility: searchable,
|
visibility: searchable,
|
||||||
|
@ -869,7 +870,6 @@ mod api {
|
||||||
source_icon: Some(git),
|
source_icon: Some(git),
|
||||||
vid_count: 0,
|
vid_count: 0,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
updated_at: "[date]",
|
|
||||||
)
|
)
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
@ -918,6 +918,7 @@ mod api {
|
||||||
Website(
|
Website(
|
||||||
name: "Test",
|
name: "Test",
|
||||||
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
created_at: (2023, 49, 16, 30, 0, 0, 0, 0, 0),
|
||||||
|
updated_at: "[date]",
|
||||||
latest_version: Some(2),
|
latest_version: Some(2),
|
||||||
color: Some(1000),
|
color: Some(1000),
|
||||||
visibility: searchable,
|
visibility: searchable,
|
||||||
|
@ -925,7 +926,6 @@ mod api {
|
||||||
source_icon: Some(git),
|
source_icon: Some(git),
|
||||||
vid_count: 2,
|
vid_count: 2,
|
||||||
has_icon: false,
|
has_icon: false,
|
||||||
updated_at: "[date]",
|
|
||||||
)
|
)
|
||||||
"###);
|
"###);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
closeSearch();
|
closeSearch();
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchKeypress(e: KeyboardEvent) {
|
function searchKeyup(e: KeyboardEvent) {
|
||||||
switch (e.key) {
|
switch (e.key) {
|
||||||
case "Enter":
|
case "Enter":
|
||||||
if (!searchText) {
|
if (!searchText) {
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
active={searchOpen || Boolean(searchText).valueOf()}
|
active={searchOpen || Boolean(searchText).valueOf()}
|
||||||
on:click={openSearch}
|
on:click={openSearch}
|
||||||
on:focusout={closeSearch}
|
on:focusout={closeSearch}
|
||||||
on:keyup={searchKeypress}
|
on:keyup={searchKeyup}
|
||||||
bind:input={searchInput}
|
bind:input={searchInput}
|
||||||
bind:text={searchText}
|
bind:text={searchText}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -26,7 +26,9 @@
|
||||||
bind:this={inputElm}
|
bind:this={inputElm}
|
||||||
bind:value={text}
|
bind:value={text}
|
||||||
on:focusout
|
on:focusout
|
||||||
on:keyup
|
on:keypress|stopPropagation
|
||||||
|
on:keydown|stopPropagation
|
||||||
|
on:keyup|stopPropagation
|
||||||
use:selectTextOnFocus
|
use:selectTextOnFocus
|
||||||
/>
|
/>
|
||||||
<Icon iconName="search" size={40} scale={0.6} />
|
<Icon iconName="search" size={40} scale={0.6} />
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import Icon from "./Icon.svelte";
|
import Icon from "./Icon.svelte";
|
||||||
import type { Website } from "talon-client";
|
import type { Website } from "talon-client";
|
||||||
import { talonConfig } from "../util/talonData";
|
import { talonConfig } from "../util/talonData";
|
||||||
|
import { getAbbreviation } from "../util/functions";
|
||||||
|
|
||||||
export let website: Website;
|
export let website: Website;
|
||||||
export let size = 40;
|
export let size = 40;
|
||||||
|
@ -15,7 +16,7 @@
|
||||||
? `${talonConfig.internal}/icons/${website.subdomain}`
|
? `${talonConfig.internal}/icons/${website.subdomain}`
|
||||||
: null}
|
: null}
|
||||||
color={website.color}
|
color={website.color}
|
||||||
alt={website.name.substring(0, 2)}
|
alt={getAbbreviation(website.name)}
|
||||||
{size}
|
{size}
|
||||||
{scale}
|
{scale}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import {
|
import {
|
||||||
formatDate,
|
formatDate,
|
||||||
getSubdomainAndVersion,
|
getSubdomainAndVersion,
|
||||||
|
getWebsiteUrl,
|
||||||
getWebsiteVersionUrl,
|
getWebsiteVersionUrl,
|
||||||
isUrl,
|
isUrl,
|
||||||
trimCommit,
|
trimCommit,
|
||||||
|
@ -75,9 +76,7 @@
|
||||||
Current version #{currentVersion.id}
|
Current version #{currentVersion.id}
|
||||||
|
|
||||||
{#if latestVersion && latestVersion !== currentVersion}
|
{#if latestVersion && latestVersion !== currentVersion}
|
||||||
<a
|
<a class="latest-tag" href={getWebsiteUrl(currentWebsite.subdomain)}
|
||||||
class="latest-tag"
|
|
||||||
href={getWebsiteVersionUrl(currentWebsite.subdomain, latestVersion.id)}
|
|
||||||
>Latest: #{latestVersion.id}</a
|
>Latest: #{latestVersion.id}</a
|
||||||
>
|
>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -81,3 +81,23 @@ export function trimCommit(commit: string | undefined): string | undefined {
|
||||||
export function isMobile(): boolean {
|
export function isMobile(): boolean {
|
||||||
return window.innerWidth < 768;
|
return window.innerWidth < 768;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a 2-letter abbreviation of the website name.
|
||||||
|
*
|
||||||
|
* If the name consists of multiple words
|
||||||
|
* (separated by spaces, underscores or CamelCase), output
|
||||||
|
* the first letters of these words.
|
||||||
|
*
|
||||||
|
* Otherwise output the first letters of the name.
|
||||||
|
*/
|
||||||
|
export function getAbbreviation(name: string): string {
|
||||||
|
const split_sep = name
|
||||||
|
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
||||||
|
.split(/[ ,.;_-]/)
|
||||||
|
.filter((x) => x.length > 0);
|
||||||
|
if (split_sep.length >= 2) {
|
||||||
|
return split_sep[0].charAt(0) + split_sep[1].charAt(0);
|
||||||
|
}
|
||||||
|
return name.substring(0, 2);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue