mirror of
https://github.com/vitaliiromanenko/popcorn-md.git
synced 2026-07-22 07:45:25 +00:00
Refactor createMovieNote to use template placeholders correctly
Replaces placeholders with appropriate template syntax to ensure correct rendering in new notes. Updates template content to use correct syntax for formatting, ensuring consistency.
This commit is contained in:
parent
5f61c706b9
commit
6ce05639ed
2 changed files with 49 additions and 17 deletions
33
AGENTS.md
33
AGENTS.md
|
|
@ -260,6 +260,39 @@ this.registerInterval(
|
|||
- Settings not persisting: ensure `loadData`/`saveData` are awaited and you re-render the UI after changes.
|
||||
- Mobile-only issues: confirm you're not using desktop-only APIs; check `isDesktopOnly` and adjust.
|
||||
|
||||
## Core Rules for Git Commit Messages
|
||||
- Use imperative mood
|
||||
Write as if giving a command: “Add feature” not “Added feature” or “Adding feature”.
|
||||
- Keep subject line concise
|
||||
Limit to 50 characters max. It should summarize the change clearly.
|
||||
- Capitalize subject line
|
||||
Always start with an uppercase letter.
|
||||
- Do not end subject with punctuation
|
||||
Avoid periods, commas, or other trailing marks.
|
||||
- Separate subject from body
|
||||
Leave one blank line between them.
|
||||
- Explain the “why” in the body
|
||||
The body should clarify motivation, context, or consequences — not just repeat the subject.
|
||||
- Wrap body at 72 characters
|
||||
Improves readability in terminals and tools.
|
||||
- Be specific, not generic
|
||||
Avoid vague subjects like “Update code”. Instead: “Refactor MovieService to support IMDb IDs”.
|
||||
Examples of Good Commit Messages
|
||||
|
||||
```plane text
|
||||
Add GenreService with TMDb integration
|
||||
|
||||
Implements a new service to fetch movie genres from TMDb API.
|
||||
Supports caching and error handling. Refs #42.
|
||||
```
|
||||
|
||||
```plate text
|
||||
Fix null reference in MovieCard UI
|
||||
|
||||
Ensures default poster is loaded when CDN image is missing.
|
||||
Prevents runtime crash in Popcorn MD plugin.
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
- Obsidian sample plugin: https://github.com/obsidianmd/obsidian-sample-plugin
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import { Movie } from "../models/Movie";
|
||||
import { TFile, Vault} from "obsidian";
|
||||
|
||||
export async function createMovieNote(movie: Movie, vault: Vault, templatePath: string): Promise<TFile | null>{
|
||||
import { TFile, Vault } from "obsidian";
|
||||
|
||||
export async function createMovieNote(movie: Movie, vault: Vault, templatePath: string): Promise<TFile | null> {
|
||||
const templateFile = vault.getAbstractFileByPath(templatePath);
|
||||
if (!(templateFile instanceof TFile)) {
|
||||
console.error("Template file not found");
|
||||
|
|
@ -12,29 +11,29 @@ export async function createMovieNote(movie: Movie, vault: Vault, templatePath:
|
|||
const templateContent = await vault.read(templateFile);
|
||||
|
||||
const noteContent = templateContent
|
||||
.replace('"{{adult}}"', String(movie.adult))
|
||||
.replace('"{{collection}}"', movie.belongs_to_collection?.name ?? "")
|
||||
.replace('"{{budget}}"', String(movie.budget))
|
||||
.replace('"{{genres}}"', `[${movie.genres.map(g => `"${g.name}"`).join(", ")}]`)
|
||||
.replace('"{{adult}}"', movie.adult ? "true" : "false")
|
||||
.replace('"{{collection}}"', `"${movie.belongs_to_collection?.name ?? ""}"`)
|
||||
.replace('"{{budget}}"', `"${String(movie.budget ?? "")}"`)
|
||||
.replace('"{{genres}}"', `[${movie.genres.map(g => `"[[${g.name}]]"`).join(", ")}]`)
|
||||
.replace('"{{homepage}}"', movie.homepage ?? "")
|
||||
.replace('"{{id}}"', String(movie.id))
|
||||
.replace('"{{id}}"', String(movie.id ?? ""))
|
||||
.replace('"{{imdb_id}}"', movie.imdb_id ?? "")
|
||||
.replace('"{{origin_country}}"', `[${movie.origin_country?.join(", ") ?? ""}]`)
|
||||
.replace('"{{origin_country}}"', `[${movie.origin_country?.map(c => `"[[${c}]]"`).join(", ") ?? ""}]`)
|
||||
.replace('"{{original_language}}"', movie.original_language ?? "")
|
||||
.replace('"{{original_title}}"', movie.original_title ?? "")
|
||||
.replace('"{{overview}}"', movie.overview ?? "")
|
||||
.replace('"{{original_title}}"', `'${movie.original_title ?? ""}'`)
|
||||
.replace('"{{overview}}"', `'${movie.overview ?? ""}'`)
|
||||
.replace('"{{popularity}}"', String(movie.popularity))
|
||||
.replace('"{{poster_path}}"', movie.poster_path ?? "")
|
||||
.replace('"{{production_companies}}"', `[${movie.production_companies.map(c => c.name).join(", ")}]`)
|
||||
.replace('"{{production_countries}}"', `[${movie.production_countries.map(c => c.name).join(", ")}]`)
|
||||
.replace('"{{production_companies}}"', `[${movie.production_companies.map(c => `"[[${c.name}]]"`).join(", ")}]`)
|
||||
.replace('"{{production_countries}}"', `[${movie.production_countries.map(c => `"[[${c.name}]]"`).join(", ")}]`)
|
||||
.replace('"{{release_date}}"', formatDate(movie.release_date) ?? "")
|
||||
.replace('"{{revenue}}"', String(movie.revenue))
|
||||
.replace('"{{runtime}}"', String(movie.runtime))
|
||||
.replace('"{{softcore}}"', String(movie.softcore ?? ""))
|
||||
.replace('"{{spoken_languages}}"', `[${movie.spoken_languages.map(l => l.name).join(", ")}]`)
|
||||
.replace('"{{spoken_languages}}"', `[${movie.spoken_languages.map(l => `"[[${l.name}]]"`).join(", ")}]`)
|
||||
.replace('"{{status}}"', movie.status ?? "")
|
||||
.replace('"{{tagline}}"', movie.tagline ?? "")
|
||||
.replace('"{{title}}"', movie.title ?? "")
|
||||
.replace('"{{tagline}}"', `'${movie.tagline ?? ""}'`)
|
||||
.replace('"{{title}}"', `'${movie.title ?? ""}'`)
|
||||
.replace('"{{vote_average}}"', String(movie.vote_average))
|
||||
.replace('"{{vote_count}}"', String(movie.vote_count));
|
||||
|
||||
|
|
@ -46,4 +45,4 @@ export async function createMovieNote(movie: Movie, vault: Vault, templatePath:
|
|||
function formatDate(dateStr: string, locale: string = "default", options?: Intl.DateTimeFormatOptions): string {
|
||||
const date = new Date(dateStr);
|
||||
return date.toLocaleDateString(locale, options);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue