mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +00:00
feat: sponsor benefits
This commit is contained in:
parent
cf8b9d8cfa
commit
1c3fdf5b60
11 changed files with 106 additions and 14 deletions
|
@ -275,6 +275,7 @@ Thank you ❤️
|
|||
- [Norbert Melzer](https://github.com/NobbZ).
|
||||
- [Patrick Stevens](https://github.com/Smaug123).
|
||||
- [Connor Baker](https://github.com/ConnorBaker).
|
||||
- [Matthew Kenigsberg](https://github.com/mkenigs).
|
||||
- [Florian Finkernagel](https://github.com/TyberiusPrime).
|
||||
|
||||
## Footnotes
|
||||
|
|
|
@ -15,7 +15,10 @@ futures = { version = "*", default_features = false, features = [
|
|||
"thread-pool"
|
||||
] }
|
||||
num_cpus = { version = "*", default_features = false, features = [] }
|
||||
rand = { version = "*", default-features = false, features = ["getrandom"] }
|
||||
rand = { version = "*", default-features = false, features = [
|
||||
"alloc",
|
||||
"getrandom"
|
||||
] }
|
||||
walkdir = { version = "*", default_features = false, features = [] }
|
||||
|
||||
[package]
|
||||
|
|
2
src/alejandra_cli/src/ads/contributor_thanks.txt
Normal file
2
src/alejandra_cli/src/ads/contributor_thanks.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
👏 Special thanks to {name} for helping improve this project:
|
||||
https://github.com/{github}
|
|
@ -1,2 +0,0 @@
|
|||
If Alejandra is useful to you, please sponsor its author.
|
||||
Thank you! https://github.com/sponsors/kamadorueda
|
|
@ -1,11 +1,94 @@
|
|||
use rand::distributions::weighted::WeightedIndex;
|
||||
use rand::distributions::Distribution;
|
||||
use rand::distributions::Uniform;
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
pub(crate) fn random_ad() -> &'static str {
|
||||
let ads = [include_str!("star.txt"), include_str!("donation.txt")];
|
||||
pub(crate) fn random_ad() -> String {
|
||||
let ads = [
|
||||
// 90% distributed proportional to total past and present contributions
|
||||
// (0.9001, sponsor_benefits as fn() -> String),
|
||||
// 10% is reserved for everything else
|
||||
(0.0333, contributor_thanks as fn() -> String),
|
||||
(0.0333, please_sponsor as fn() -> String),
|
||||
(0.0333, please_star as fn() -> String),
|
||||
];
|
||||
|
||||
let ads_index = Uniform::from(0..ads.len()).sample(&mut OsRng);
|
||||
|
||||
ads[ads_index]
|
||||
random_weighted_choice(&ads[..])()
|
||||
}
|
||||
|
||||
fn sponsor_benefits() -> String {
|
||||
#[allow(dead_code)]
|
||||
enum Sponsor<'a> {
|
||||
Individual { name: &'a str },
|
||||
Company { ad: &'a str },
|
||||
}
|
||||
|
||||
let sponsors = [];
|
||||
|
||||
match random_weighted_choice(&sponsors[..]) {
|
||||
Sponsor::Company { ad } => {
|
||||
include_str!("sponsor_advertisement.txt").replace("{ad}", ad)
|
||||
},
|
||||
Sponsor::Individual { name } => {
|
||||
include_str!("sponsor_thanks.txt").replace("{name}", name)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn contributor_thanks() -> String {
|
||||
let names = [
|
||||
(1.0, ("Connor Baker", "ConnorBaker")),
|
||||
(1.0, ("David Arnold", "blaggacao")),
|
||||
(1.0, ("David Hauer", "DavHau")),
|
||||
(1.0, ("Fabian Möller", "B4dM4n")),
|
||||
(1.0, ("Florian Finkernagel", "TyberiusPrime")),
|
||||
(1.0, ("Jamie Quigley", "Sciencentistguy")),
|
||||
(1.0, ("Joachim Ernst", "0x4A6F")),
|
||||
(1.0, ("Jörg Thalheim", "Mic92")),
|
||||
(1.0, ("Kevin Amado", "kamadorueda")),
|
||||
(1.0, ("Loïc Reynier", "loicreynier")),
|
||||
(1.0, ("Matthew Kenigsberg", "mkenigs")),
|
||||
(1.0, ("Mr Hedgehog", "ModdedGamers")),
|
||||
(1.0, ("Norbert Melzer", "NobbZ")),
|
||||
(1.0, ("Patrick Stevens", "Smaug123")),
|
||||
(1.0, ("Piegames", "piegamesde")),
|
||||
(1.0, ("Rehno Lindeque", "rehno-lindeque")),
|
||||
(1.0, ("Rok Garbas", "garbas")),
|
||||
(1.0, ("Ryan Mulligan", "ryantm")),
|
||||
(1.0, ("Thomas Bereknyei", "tomberek")),
|
||||
(1.0, ("Tristan Maat", "TLATER")),
|
||||
(1.0, ("Vincent Ambo", "tazjin")),
|
||||
(1.0, ("Yorick van Pelt", "yorickvP")),
|
||||
];
|
||||
|
||||
let (name, github) = random_weighted_choice(&names[..]);
|
||||
|
||||
include_str!("contributor_thanks.txt")
|
||||
.replace("{github}", github)
|
||||
.replace("{name}", name)
|
||||
}
|
||||
|
||||
fn please_sponsor() -> String {
|
||||
let messages = [
|
||||
(0.5000, include_str!("sponsor_advertisement.txt").replace(
|
||||
"{ad}",
|
||||
concat!(
|
||||
"Advertise your company here, reach lots of active Nix users!\n",
|
||||
"More information at: https://github.com/sponsors/kamadorueda\n"
|
||||
),
|
||||
)),
|
||||
(0.5000, include_str!("please_sponsor.txt").to_string()),
|
||||
];
|
||||
|
||||
random_weighted_choice(&messages[..]).clone()
|
||||
}
|
||||
|
||||
fn please_star() -> String {
|
||||
include_str!("please_star.txt").to_string()
|
||||
}
|
||||
|
||||
fn random_weighted_choice<T>(choices: &[(f64, T)]) -> &T {
|
||||
let weights = choices.iter().map(|(weight, _)| *weight);
|
||||
let index: usize = WeightedIndex::new(weights).unwrap().sample(&mut OsRng);
|
||||
|
||||
&choices[index].1
|
||||
}
|
||||
|
|
2
src/alejandra_cli/src/ads/please_sponsor.txt
Normal file
2
src/alejandra_cli/src/ads/please_sponsor.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
🤟 If Alejandra is useful to you, please consider sponsoring its author!
|
||||
There are cool benefits for you: https://github.com/sponsors/kamadorueda
|
2
src/alejandra_cli/src/ads/please_star.txt
Normal file
2
src/alejandra_cli/src/ads/please_star.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
⭐ If Alejandra is useful to you, please add your star to the repository.
|
||||
Thank you! https://github.com/kamadorueda/alejandra
|
1
src/alejandra_cli/src/ads/sponsor_advertisement.txt
Normal file
1
src/alejandra_cli/src/ads/sponsor_advertisement.txt
Normal file
|
@ -0,0 +1 @@
|
|||
👉 [Sponsored] {ad}
|
1
src/alejandra_cli/src/ads/sponsor_thanks.txt
Normal file
1
src/alejandra_cli/src/ads/sponsor_thanks.txt
Normal file
|
@ -0,0 +1 @@
|
|||
👏 Special thanks to {name} for being a sponsor of Alejandra!
|
|
@ -1,2 +0,0 @@
|
|||
If Alejandra is useful to you, please add your star to the repository.
|
||||
Thank you! https://github.com/kamadorueda/alejandra
|
|
@ -87,8 +87,7 @@ fn format_paths(
|
|||
|
||||
if verbosity.allows_info() {
|
||||
eprintln!(
|
||||
"{} {paths_len} file{} using {threads} thread{}.",
|
||||
"Checking style in",
|
||||
"Checking style in {paths_len} file{} using {threads} thread{}.",
|
||||
if paths_len == 1 { "" } else { "s" },
|
||||
if threads == 1 { "" } else { "s" },
|
||||
);
|
||||
|
@ -218,7 +217,9 @@ pub fn main() -> std::io::Result<()> {
|
|||
|
||||
if verbosity.allows_info() {
|
||||
eprintln!();
|
||||
eprintln!("Congratulations! Your code complies with the Alejandra style.");
|
||||
eprintln!(
|
||||
"Congratulations! Your code complies with the Alejandra style."
|
||||
);
|
||||
eprintln!();
|
||||
eprint!("{}", random_ad());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue