| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
use super::SeedError; |
| 10 |
use super::projects::SeededProject; |
| 11 |
use crate::db; |
| 12 |
use crate::formatting::slugify; |
| 13 |
use crate::markdown::render_creator_markdown; |
| 14 |
|
| 15 |
|
| 16 |
pub async fn seed_blog(pool: &sqlx::PgPool, projects: &[SeededProject]) -> Result<(), SeedError> { |
| 17 |
for project in projects { |
| 18 |
for post in project.spec.blog { |
| 19 |
let slug = slugify(post.title); |
| 20 |
|
| 21 |
|
| 22 |
let body_html = render_creator_markdown(post.body, project.user_id, ""); |
| 23 |
db::blog_posts::create_blog_post( |
| 24 |
pool, |
| 25 |
project.project.id, |
| 26 |
project.user_id, |
| 27 |
post.title, |
| 28 |
&slug, |
| 29 |
post.body, |
| 30 |
&body_html, |
| 31 |
true, |
| 32 |
false, |
| 33 |
false, |
| 34 |
) |
| 35 |
.await?; |
| 36 |
tracing::info!(title = post.title, slug = %slug, "example seed: published blog post"); |
| 37 |
} |
| 38 |
} |
| 39 |
Ok(()) |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
const CREDITS_PROJECT_SLUG: &str = "commons-sampler"; |
| 46 |
|
| 47 |
|
| 48 |
const CREDITS_TITLE: &str = "Media credits and sources"; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
pub async fn seed_media_credits( |
| 62 |
pool: &sqlx::PgPool, |
| 63 |
projects: &[SeededProject], |
| 64 |
assets: &super::manifest::ResolvedAssets, |
| 65 |
) -> Result<(), SeedError> { |
| 66 |
let list = assets.attribution_markdown(); |
| 67 |
if list.is_empty() { |
| 68 |
tracing::info!("example seed: no curated media, skipping the credits post"); |
| 69 |
return Ok(()); |
| 70 |
} |
| 71 |
let Some(project) = projects |
| 72 |
.iter() |
| 73 |
.find(|p| p.spec.slug == CREDITS_PROJECT_SLUG) |
| 74 |
else { |
| 75 |
tracing::warn!( |
| 76 |
slug = CREDITS_PROJECT_SLUG, |
| 77 |
"example seed: credits project missing from the roster; credits not published" |
| 78 |
); |
| 79 |
return Ok(()); |
| 80 |
}; |
| 81 |
|
| 82 |
let body = format!( |
| 83 |
"Every file on this demo is public domain or CC0. This is where each one \ |
| 84 |
came from.\n\n{list}\n\nNothing here is a real listing. The catalog is \ |
| 85 |
fabricated for demonstration; only the media is real, and only because \ |
| 86 |
its licence allows it." |
| 87 |
); |
| 88 |
let slug = slugify(CREDITS_TITLE); |
| 89 |
let body_html = render_creator_markdown(&body, project.user_id, ""); |
| 90 |
db::blog_posts::create_blog_post( |
| 91 |
pool, |
| 92 |
project.project.id, |
| 93 |
project.user_id, |
| 94 |
CREDITS_TITLE, |
| 95 |
&slug, |
| 96 |
&body, |
| 97 |
&body_html, |
| 98 |
true, |
| 99 |
false, |
| 100 |
false, |
| 101 |
) |
| 102 |
.await?; |
| 103 |
tracing::info!( |
| 104 |
assets = assets.len(), |
| 105 |
slug = %slug, |
| 106 |
"example seed: published media credits" |
| 107 |
); |
| 108 |
Ok(()) |
| 109 |
} |
| 110 |
|