cinera.c: Use html_title in Welcome / End markers

This commit is contained in:
Matt Mascarenhas 2021-10-06 15:45:19 +01:00
parent ee788b0c30
commit 4dc034ecc3
1 changed files with 31 additions and 26 deletions

View File

@ -23,7 +23,7 @@ typedef struct
version CINERA_APP_VERSION = { version CINERA_APP_VERSION = {
.Major = 0, .Major = 0,
.Minor = 10, .Minor = 10,
.Patch = 1 .Patch = 2
}; };
#include <stdarg.h> // NOTE(matt): varargs #include <stdarg.h> // NOTE(matt): varargs
@ -9960,6 +9960,26 @@ GetNumberFromHMMLBaseFilename(string ProjectID, string HMMLBaseFilename)
return Result; return Result;
} }
string
BestTitleForHTML(project *Project)
{
return Project->HTMLTitle.Length ? Project->HTMLTitle : Project->Title;
}
void
CopyProjectWelcomeStringToBuffer(buffer *B, string ProjectTitle)
{
CopyStringToBuffer(B,
" <div class=\"episodeMarker first\"><div>&#8226;</div><div>Welcome to <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)ProjectTitle.Length, ProjectTitle.Base);
}
void
CopyProjectEndStringToBuffer(buffer *B, string ProjectTitle)
{
CopyStringToBuffer(B,
" <div class=\"episodeMarker last\"><div>&#8226;</div><div>You have arrived at the (current) end of <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)ProjectTitle.Length, ProjectTitle.Base);
}
rc rc
HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseFilename, neighbourhood *N) HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseFilename, neighbourhood *N)
{ {
@ -10127,15 +10147,7 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF
Result = RC_ERROR_HMML; Result = RC_ERROR_HMML;
} }
string ProjectTitle; string ProjectTitle = BestTitleForHTML(CurrentProject);
if(CurrentProject->HTMLTitle.Length)
{
ProjectTitle = CurrentProject->HTMLTitle;
}
else
{
ProjectTitle = CurrentProject->Title;
}
// TODO(matt): Handle the art and art_variants once .hmml supports them // TODO(matt): Handle the art and art_variants once .hmml supports them
@ -10295,8 +10307,7 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF
} }
else else
{ {
CopyStringToBuffer(&PlayerBuffers.Main, CopyProjectWelcomeStringToBuffer(&PlayerBuffers.Main, ProjectTitle);
" <div class=\"episodeMarker first\"><div>&#8226;</div><div>Welcome to <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)ProjectTitle.Length, ProjectTitle.Base);
} }
} }
N->WorkingThis.LinkOffsets.PrevEnd = (PlayerBuffers.Main.Ptr - PlayerBuffers.Main.Location - N->WorkingThis.LinkOffsets.PrevStart); N->WorkingThis.LinkOffsets.PrevEnd = (PlayerBuffers.Main.Ptr - PlayerBuffers.Main.Location - N->WorkingThis.LinkOffsets.PrevStart);
@ -10701,8 +10712,7 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF
} }
else else
{ {
CopyStringToBuffer(&PlayerBuffers.Main, CopyProjectEndStringToBuffer(&PlayerBuffers.Main, ProjectTitle);
" <div class=\"episodeMarker last\"><div>&#8226;</div><div>You have arrived at the (current) end of <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)ProjectTitle.Length, ProjectTitle.Base);
} }
} }
N->WorkingThis.LinkOffsets.NextEnd = (PlayerBuffers.Main.Ptr - PlayerBuffers.Main.Location - (N->WorkingThis.LinkOffsets.PrevStart + N->WorkingThis.LinkOffsets.PrevEnd + N->WorkingThis.LinkOffsets.NextStart)); N->WorkingThis.LinkOffsets.NextEnd = (PlayerBuffers.Main.Ptr - PlayerBuffers.Main.Location - (N->WorkingThis.LinkOffsets.PrevStart + N->WorkingThis.LinkOffsets.PrevEnd + N->WorkingThis.LinkOffsets.NextStart));
@ -12761,6 +12771,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li
ConstructPlayerURL(&ToPlayerURL, P, Wrap0i(To->OutputLocation, sizeof(To->OutputLocation))); ConstructPlayerURL(&ToPlayerURL, P, Wrap0i(To->OutputLocation, sizeof(To->OutputLocation)));
} }
string ProjectTitle = BestTitleForHTML(CurrentProject);
int NewPrevEnd = 0; int NewPrevEnd = 0;
int NewNextEnd = 0; int NewNextEnd = 0;
switch(LinkDirection) switch(LinkDirection)
@ -12778,8 +12789,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li
else else
{ {
// TODO(matt): Be careful of this! Is this CurrentProject->Title definitely set to the right thing? // TODO(matt): Be careful of this! Is this CurrentProject->Title definitely set to the right thing?
CopyStringToBuffer(&Link, CopyProjectWelcomeStringToBuffer(&Link, ProjectTitle);
" <div class=\"episodeMarker first\"><div>&#8226;</div><div>Welcome to <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base);
} }
NewPrevEnd = Link.Ptr - Link.Location; NewPrevEnd = Link.Ptr - Link.Location;
fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle); fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle);
@ -12787,8 +12797,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li
{ {
fwrite(HTML.Buffer.Location + From->LinkOffsets.PrevStart + From->LinkOffsets.PrevEnd, From->LinkOffsets.NextStart, 1, HTML.Handle); fwrite(HTML.Buffer.Location + From->LinkOffsets.PrevStart + From->LinkOffsets.PrevEnd, From->LinkOffsets.NextStart, 1, HTML.Handle);
RewindBuffer(&Link); RewindBuffer(&Link);
CopyStringToBuffer(&Link, CopyProjectEndStringToBuffer(&Link, ProjectTitle);
" <div class=\"episodeMarker last\"><div>&#8226;</div><div>You have arrived at the (current) end of <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base);
NewNextEnd = Link.Ptr - Link.Location; NewNextEnd = Link.Ptr - Link.Location;
fwrite(Link.Location, NewNextEnd, 1, HTML.Handle); fwrite(Link.Location, NewNextEnd, 1, HTML.Handle);
fwrite(HTML.Buffer.Location + From->LinkOffsets.PrevStart + From->LinkOffsets.PrevEnd + From->LinkOffsets.NextStart + From->LinkOffsets.NextEnd, fwrite(HTML.Buffer.Location + From->LinkOffsets.PrevStart + From->LinkOffsets.PrevEnd + From->LinkOffsets.NextStart + From->LinkOffsets.NextEnd,
@ -12812,8 +12821,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li
if(FromHasOneNeighbour) if(FromHasOneNeighbour)
{ {
fwrite(HTML.Buffer.Location, From->LinkOffsets.PrevStart, 1, HTML.Handle); fwrite(HTML.Buffer.Location, From->LinkOffsets.PrevStart, 1, HTML.Handle);
CopyStringToBuffer(&Link, CopyProjectWelcomeStringToBuffer(&Link, ProjectTitle);
" <div class=\"episodeMarker first\"><div>&#8226;</div><div>Welcome to <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base);
NewPrevEnd = Link.Ptr - Link.Location; NewPrevEnd = Link.Ptr - Link.Location;
fwrite(Link.Location, NewPrevEnd, 1, HTML.Handle); fwrite(Link.Location, NewPrevEnd, 1, HTML.Handle);
RewindBuffer(&Link); RewindBuffer(&Link);
@ -12834,8 +12842,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li
} }
else else
{ {
CopyStringToBuffer(&Link, CopyProjectEndStringToBuffer(&Link, ProjectTitle);
" <div class=\"episodeMarker last\"><div>&#8226;</div><div>You have arrived at the (current) end of <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base);
} }
NewNextEnd = Link.Ptr - Link.Location; NewNextEnd = Link.Ptr - Link.Location;
fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle); fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle);
@ -12974,8 +12981,7 @@ MarkNextAsFirst(neighbourhood *N)
fwrite(HTML.Buffer.Location, N->Next->LinkOffsets.PrevStart, 1, HTML.Handle); fwrite(HTML.Buffer.Location, N->Next->LinkOffsets.PrevStart, 1, HTML.Handle);
CopyStringToBuffer(&Link, CopyProjectWelcomeStringToBuffer(&Link, BestTitleForHTML(CurrentProject));
" <div class=\"episodeMarker first\"><div>&#8226;</div><div>Welcome to <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base);
fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle); fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle);
@ -13013,8 +13019,7 @@ MarkPrevAsFinal(neighbourhood *N)
fwrite(HTML.Buffer.Location, N->Prev->LinkOffsets.PrevStart + N->Prev->LinkOffsets.PrevEnd + N->Prev->LinkOffsets.NextStart, 1, HTML.Handle); fwrite(HTML.Buffer.Location, N->Prev->LinkOffsets.PrevStart + N->Prev->LinkOffsets.PrevEnd + N->Prev->LinkOffsets.NextStart, 1, HTML.Handle);
CopyStringToBuffer(&Link, CopyProjectEndStringToBuffer(&Link, BestTitleForHTML(CurrentProject));
" <div class=\"episodeMarker last\"><div>&#8226;</div><div>You have arrived at the (current) end of <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)CurrentProject->Title.Length, CurrentProject->Title.Base);
fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle); fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle);