Commit b61fc119 authored by Matt Mascarenhas's avatar Matt Mascarenhas

hmml_to_html.c: Introduce BuildQuote() [#20]

Also move some structural styling out to style.css
parent d34ad0a0
......@@ -38,6 +38,12 @@ typedef struct
int IdentifierCount;
} ref_info;
typedef struct
{
char Date[32];
char Text[512];
} quote_info;
#define ArrayCount(A) sizeof(A)/sizeof(*(A))
void
......@@ -337,6 +343,94 @@ BuildCategories(buffer *AnnotationClass, buffer *Category, int *MarkerIndex, boo
return;
}
#define QUOTE_DIR "/home/matt/git/GitHub/insofaras/25fc16d58a297a486334"
int
StringToInt(char *String)
{
int Result = 0;
while(*String)
{
Result = Result * 10 + (*String - '0');
++String;
}
return Result;
}
int
BuildQuote(quote_info *Info, char *Speaker, int ID)
{
char Path[255] = {0};
sprintf(Path, "%s/#%s", QUOTE_DIR, Speaker);
FILE *File;
if(!(File = fopen(Path, "r")))
{
perror("hmml_to_html");
return 1;
}
fseek(File, 0, SEEK_END);
int Length = ftell(File);
fseek(File, 0, SEEK_SET);
char *Buffer;
if(!(Buffer = malloc(Length)))
{
perror("hmml_to_html");
}
fread(Buffer, Length, 1, File);
fclose(File);
char *InPtr = Buffer;
while(InPtr - Buffer < Length)
{
char InID[4] = {0};
char *OutPtr = InID;
while(*InPtr != ',')
{
*OutPtr++ = *InPtr++;
}
*OutPtr = '\0';
if(StringToInt(InID) == ID)
{
InPtr += 2;
OutPtr = Info->Date;
while(*InPtr != '"')
{
*OutPtr++ = *InPtr++;
}
*OutPtr = '\0';
InPtr += 3;
OutPtr = Info->Text;
while(*InPtr != '\n')
{
if(*InPtr == '\\')
{
++InPtr;
}
*OutPtr++ = *InPtr++;
}
*--OutPtr = '\0';
free(Buffer);
return 0;
}
else
{
while(*InPtr != '\n')
{
++InPtr;
}
++InPtr;
}
}
free(Buffer);
return 1;
}
void
GenerateTopicColours(buffer *Colour, char *Topic)
{
......@@ -477,6 +571,8 @@ main(int ArgC, char **Args)
bool HasQuote = FALSE;
bool HasReference = FALSE;
quote_info QuoteInfo = { 0 };
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationHeader, 512);
ClaimBuffer(MemoryArena, &ClaimedMemory, &Category, 256);
ClaimBuffer(MemoryArena, &ClaimedMemory, &AnnotationClass, 256);
......@@ -687,11 +783,25 @@ AppendedIdentifier:
HasQuote = TRUE;
if(BuildQuote(&QuoteInfo, HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member, Anno->quote.id) == 1)
{
fprintf(stderr, "%s:%d: Quote #%s %d not found! Consider pulling the latest quotes\n",
Args[FileIndex],
Anno->line,
HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member,
Anno->quote.id);
hmml_free(&HMML);
free(MemoryArena);
return 1;
}
CopyStringToBuffer(&QuoteMenu,
" <span data-id=\"&#%d;\" class=\"ref\">\n"
" <span class=\"ref_content\">\n"
" <div class=\"source\">#%d • %s</div>\n"
" <div class=\"source\">Quote %d</div>\n"
" <div class=\"ref_title\">%s</div>\n"
" <div class=\"quote_byline\">&mdash;%s, %s</div>\n"
" </span>\n"
" <div class=\"ref_indices\">\n"
" <span data-timestamp=\"%d\" class=\"timecode\"><span class=\"ref_index\">[&#%d;]</span><span class=\"time\">%s</span></span>\n"
......@@ -699,14 +809,15 @@ AppendedIdentifier:
" </span>\n",
QuoteIdentifier,
Anno->quote.id,
"Quote date",
"Quote text",
QuoteInfo.Text,
HMML.metadata.twitch ? HMML.metadata.twitch : HMML.metadata.member,
QuoteInfo.Date,
TimecodeToSeconds(Anno->time),
QuoteIdentifier,
Anno->time);
if(!Anno->text[0])
{
CopyStringToBuffer(&Text, "&#8220;Quote text&#8221;");
CopyStringToBuffer(&Text, "&#8220;%s&#8221;", QuoteInfo.Text);
}
CopyStringToBuffer(&Text, "<sup>&#%d;</sup>", QuoteIdentifier);
++QuoteIdentifier;
......
......@@ -7,7 +7,7 @@
.title.obbg {
background-color: #EEE;
color: #000;
border-bottom: 1px solid #372F46;
border-color: #372F46;
}
.title.obbg .refs_container {
......@@ -25,12 +25,11 @@
.title.obbg .refs_container .refs {
background-color: #EEE;
border: 2px solid #372F46;
border-top: none;
border-color: #372F46;
}
.title.obbg .refs_container > .refs .ref {
border-bottom: 1px solid #372F46;
border-color: #372F46;
color: #000000;
}
......@@ -40,17 +39,21 @@
}
.title.obbg .refs_container > .refs .ref:hover {
background-color: #FFF8E7;
background-color: #DDD;
}
.title.obbg .refs_container > .refs .ref.current:hover {
background-color: rgba(55, 46, 65, 0.7);
background-color: #68557E;
}
.title.obbg .refs_container > .refs .ref .source {
color: #888;
}
.title.obbg .refs_container > .refs .ref .quote_byline {
color: #888;
}
.title.obbg .refs_container > .refs .ref.current .source {
color: #FFF8E7;
}
......@@ -61,7 +64,7 @@
}
.markers_container.obbg > .marker {
border-bottom: 1px solid #888;
border-color: #888;
}
.markers_container.obbg > .marker:hover > .content {
......
.title.riscy {
background-color: #EEE;
color: #000000;
border-bottom: 1px solid rgba(246, 178, 26, 0.8);
border-color: rgba(246, 178, 26, 0.8);
}
.title.riscy .refs_container {
......@@ -19,12 +19,11 @@
.title.riscy .refs_container .refs {
background-color: #EEE;
border: 2px solid rgba(246, 178, 26, 0.8);
border-top: none;
border-color: rgba(246, 178, 26, 0.8);
}
.title.riscy .refs_container > .refs .ref {
border-bottom: 1px solid rgba(246, 178, 26, 0.8);
border-color: rgba(246, 178, 26, 0.8);
color: #000000;
}
......@@ -45,6 +44,10 @@
color: #888;
}
.title.riscy .refs_container > .refs .ref .quote_byline {
color: #888;
}
.title.riscy .refs_container > .refs .ref.current .source {
color: #FFF8E7;
}
......@@ -55,7 +58,7 @@
}
.markers_container.riscy > .marker {
border-bottom: 1px solid rgba(246, 178, 26, 0.8);
border-color: rgba(246, 178, 26, 0.8);
}
.markers_container.riscy > .marker:hover > .content {
......
......@@ -3,6 +3,7 @@
.title {
display: flex;
flex-direction: row;
border-bottom: 1px solid;
}
.title > * {
......@@ -26,6 +27,8 @@
}
.title .refs_container .refs {
border: 2px solid;
border-top:none;
position: absolute;
top: 100%;
right: 0;
......@@ -39,6 +42,7 @@
}
.title .refs_container > .refs .ref {
border-bottom: 1px solid;
padding: 10px;
display: flex;
flex-direction: column;
......@@ -56,6 +60,31 @@
padding: 0;
}
.title .refs_container > .refs .ref .timecode:hover .time {
text-decoration: underline;
}
.title .refs_container > .refs .ref .ref_content {
margin-bottom: 8px;
width: 100%;
}
.title .refs_container > .refs .ref .source {
font-size: 10px;
line-height: 8px;
}
.title .refs_container > .refs .ref .ref_title {
font-style: oblique;
}
.title .refs_container > .refs .ref .quote_byline {
font-size: 10px;
line-height: 8px;
text-align: right;
width: 100%;
}
.title .refs_container > .refs .ref .ref_indices {
text-align: center;
}
......@@ -74,23 +103,6 @@
margin: 0 4px;
}
.title .refs_container > .refs .ref .timecode:hover .time {
text-decoration: underline;
}
.title .refs_container > .refs .ref .ref_content {
width: 100%;
}
.title .refs_container > .refs .ref .source {
font-size: 10px;
line-height: 8px;
}
.title .refs_container > .refs .ref .ref_title {
font-style: oblique;
}
.title .refs_container > .refs .ref .timecode .ref_index {
margin-right: 4px;
}
......@@ -111,6 +123,7 @@
}
.markers_container > .marker {
border-bottom: 1px solid;
position: relative;
cursor: pointer;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment