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 = {
.Major = 0,
.Minor = 10,
.Patch = 1
.Patch = 2
};
#include <stdarg.h> // NOTE(matt): varargs
@ -9960,6 +9960,26 @@ GetNumberFromHMMLBaseFilename(string ProjectID, string HMMLBaseFilename)
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
HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseFilename, neighbourhood *N)
{
@ -10127,15 +10147,7 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF
Result = RC_ERROR_HMML;
}
string ProjectTitle;
if(CurrentProject->HTMLTitle.Length)
{
ProjectTitle = CurrentProject->HTMLTitle;
}
else
{
ProjectTitle = CurrentProject->Title;
}
string ProjectTitle = BestTitleForHTML(CurrentProject);
// TODO(matt): Handle the art and art_variants once .hmml supports them
@ -10295,8 +10307,7 @@ HMMLToBuffers(buffers *CollationBuffers, template *BespokeTemplate, string BaseF
}
else
{
CopyStringToBuffer(&PlayerBuffers.Main,
" <div class=\"episodeMarker first\"><div>&#8226;</div><div>Welcome to <cite>%.*s</cite></div><div>&#8226;</div></div>\n", (int)ProjectTitle.Length, ProjectTitle.Base);
CopyProjectWelcomeStringToBuffer(&PlayerBuffers.Main, ProjectTitle);
}
}
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
{
CopyStringToBuffer(&PlayerBuffers.Main,
" <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);
CopyProjectEndStringToBuffer(&PlayerBuffers.Main, ProjectTitle);
}
}
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)));
}
string ProjectTitle = BestTitleForHTML(CurrentProject);
int NewPrevEnd = 0;
int NewNextEnd = 0;
switch(LinkDirection)
@ -12778,8 +12789,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li
else
{
// TODO(matt): Be careful of this! Is this CurrentProject->Title definitely set to the right thing?
CopyStringToBuffer(&Link,
" <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);
CopyProjectWelcomeStringToBuffer(&Link, ProjectTitle);
}
NewPrevEnd = Link.Ptr - Link.Location;
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);
RewindBuffer(&Link);
CopyStringToBuffer(&Link,
" <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);
CopyProjectEndStringToBuffer(&Link, ProjectTitle);
NewNextEnd = Link.Ptr - Link.Location;
fwrite(Link.Location, NewNextEnd, 1, HTML.Handle);
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)
{
fwrite(HTML.Buffer.Location, From->LinkOffsets.PrevStart, 1, HTML.Handle);
CopyStringToBuffer(&Link,
" <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);
CopyProjectWelcomeStringToBuffer(&Link, ProjectTitle);
NewPrevEnd = Link.Ptr - Link.Location;
fwrite(Link.Location, NewPrevEnd, 1, HTML.Handle);
RewindBuffer(&Link);
@ -12834,8 +12842,7 @@ InsertNeighbourLink(db_header_project *P, db_entry *From, db_entry *To, enum8(li
}
else
{
CopyStringToBuffer(&Link,
" <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);
CopyProjectEndStringToBuffer(&Link, ProjectTitle);
}
NewNextEnd = Link.Ptr - Link.Location;
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);
CopyStringToBuffer(&Link,
" <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);
CopyProjectWelcomeStringToBuffer(&Link, BestTitleForHTML(CurrentProject));
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);
CopyStringToBuffer(&Link,
" <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);
CopyProjectEndStringToBuffer(&Link, BestTitleForHTML(CurrentProject));
fwrite(Link.Location, (Link.Ptr - Link.Location), 1, HTML.Handle);