hmml_to_html.c: Fix URL timestamp

Also provide the ability to pass a default medium
This commit is contained in:
Matt Mascarenhas 2017-08-05 19:13:02 +01:00
parent a389423b73
commit 2059b9367a
1 changed files with 52 additions and 34 deletions

View File

@ -1,6 +1,6 @@
#if 0 #if 0
ctime -begin ${0%.*}.ctm ctime -begin ${0%.*}.ctm
gcc -g -Wall -fsanitize=address -std=c99 -pipe $0 -o ${0%.*} hmml.a gcc -g -no-pie -fsanitize=address -Wall -std=c99 -pipe $0 -o ${0%.*} hmml.a
ctime -end ${0%.*}.ctm ctime -end ${0%.*}.ctm
exit exit
#endif #endif
@ -561,15 +561,6 @@ BuildReference(ref_info *ReferencesArray, int RefIdentifier, int UniqueRefs, HMM
if(Ref.publisher) { Mask |= REF_PUBLISHER; } if(Ref.publisher) { Mask |= REF_PUBLISHER; }
if(Ref.isbn) { Mask |= REF_ISBN; } if(Ref.isbn) { Mask |= REF_ISBN; }
/*
* NOTE(matt)
*
* Mask
* Loop over the reference attributes, adding them to a mask if they are set
* Then my cases will just be that mask tested against the attributes OR'd with each other
*
*/
if((REF_URL | REF_TITLE | REF_AUTHOR | REF_PUBLISHER | REF_ISBN) == Mask) if((REF_URL | REF_TITLE | REF_AUTHOR | REF_PUBLISHER | REF_ISBN) == Mask)
{ {
CopyString(ReferencesArray[UniqueRefs].ID, Ref.isbn); CopyString(ReferencesArray[UniqueRefs].ID, Ref.isbn);
@ -652,16 +643,16 @@ BuildReference(ref_info *ReferencesArray, int RefIdentifier, int UniqueRefs, HMM
char *CategoryMedium[][3] = char *CategoryMedium[][3] =
{ {
// medium icon written name // medium icon written name
{ "afk", "…" , "Away from Keyboard"}, // TODO(matt): Filter this out by default { "afk", "…" , "Away from Keyboard"}, // TODO(matt): Filter this out by default
{ "authored", "🗪", "Chat Comment"}, // TODO(matt): Conditionally handle Chat vs Guest Comments { "authored", "🗪", "Chat Comment"}, // TODO(matt): Conditionally handle Chat vs Guest Comments
{ "blackboard", "🖌", "Blackboard"}, { "blackboard", "🖌", "Blackboard"},
{ "default", "🖮", "Programming"}, // TODO(matt): Potentially make this configurable per project { "experience", "🍷", "Experience"},
{ "experience", "🍷", "Experience"}, { "owl", "🦉", "Owl of Shame"},
{ "owl", "🦉", "Owl of Shame"}, { "programming", "🖮", "Programming"}, // TODO(matt): Potentially make this configurable per project
{ "rant", "💢", "Rant"}, { "rant", "💢", "Rant"},
{ "research", "📖", "Research"}, { "research", "📖", "Research"},
{ "run", "🏃", "In-Game"}, // TODO(matt): Potentially make this configurable per project { "run", "🏃", "In-Game"}, // TODO(matt): Potentially make this configurable per project
{ "trivia", "🎲", "Trivia"}, { "trivia", "🎲", "Trivia"},
}; };
void void
@ -1224,7 +1215,7 @@ ParseConfig(buffer *Buffer, char *Username)
#endif #endif
void void
PrintUsage(char *BinaryLocation, char *DefaultCSSDir, char *DefaultImagesDir, char *DefaultJSDir, char *DefaultOutLocation, char *DefaultQuoteDir, char *DefaultTemplateLocation) PrintUsage(char *BinaryLocation, char *DefaultCSSDir, char *DefaultImagesDir, char *DefaultJSDir, char *DefaultDefaultMedium, char *DefaultOutLocation, char *DefaultQuoteDir, char *DefaultTemplateLocation)
{ {
fprintf(stderr, "Usage: %s [option(s)] filename(s)\n" fprintf(stderr, "Usage: %s [option(s)] filename(s)\n"
"\n" "\n"
@ -1235,6 +1226,8 @@ PrintUsage(char *BinaryLocation, char *DefaultCSSDir, char *DefaultImagesDir, ch
" Override default images directory (\"%s\")\n" " Override default images directory (\"%s\")\n"
" -j <JS directory path>\n" " -j <JS directory path>\n"
" Override default JS directory (\"%s\")\n" " Override default JS directory (\"%s\")\n"
" -m <default medium>\n"
" Override default default medium (\"%s\")\n"
" -o <output location>\n" " -o <output location>\n"
" Override default output location (\"%s\")\n" " Override default output location (\"%s\")\n"
" -q <quotes directory path>\n" " -q <quotes directory path>\n"
@ -1250,7 +1243,7 @@ PrintUsage(char *BinaryLocation, char *DefaultCSSDir, char *DefaultImagesDir, ch
" CINERA_MODE\n" " CINERA_MODE\n"
" =INTEGRATE\n" " =INTEGRATE\n"
" Enable integration\n", " Enable integration\n",
BinaryLocation, DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation); BinaryLocation, DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation);
} }
int int
@ -1267,6 +1260,9 @@ main(int ArgC, char **Args)
char *DefaultJSDir = "."; char *DefaultJSDir = ".";
char *JSDir = DefaultJSDir; char *JSDir = DefaultJSDir;
char *DefaultDefaultMedium = "programming";
char *DefaultMedium = DefaultDefaultMedium;
char *DefaultTemplateLocation = "template.html"; char *DefaultTemplateLocation = "template.html";
char *TemplateLocation = DefaultTemplateLocation; char *TemplateLocation = DefaultTemplateLocation;
@ -1283,12 +1279,12 @@ main(int ArgC, char **Args)
if(ArgC < 2) if(ArgC < 2)
{ {
PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation); PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation);
return 1; return 1;
} }
char CommandLineArg; char CommandLineArg;
while((CommandLineArg = getopt(ArgC, Args, "c:i:j:o:q:t:h")) != -1) while((CommandLineArg = getopt(ArgC, Args, "c:i:j:m:o:q:t:h")) != -1)
{ {
switch(CommandLineArg) switch(CommandLineArg)
{ {
@ -1301,6 +1297,9 @@ main(int ArgC, char **Args)
case 'j': case 'j':
JSDir = optarg; JSDir = optarg;
break; break;
case 'm':
DefaultMedium = optarg;
break;
case 'o': case 'o':
OutLocation = optarg; OutLocation = optarg;
OutIntegratedLocation = optarg; OutIntegratedLocation = optarg;
@ -1315,7 +1314,7 @@ main(int ArgC, char **Args)
// Override config path, once we even have a default! // Override config path, once we even have a default!
case 'h': case 'h':
default: default:
PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation); PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation);
return 1; return 1;
} }
} }
@ -1323,7 +1322,7 @@ main(int ArgC, char **Args)
if(optind == ArgC) if(optind == ArgC)
{ {
fprintf(stderr, "%s: requires at least one input .hmml file\n", Args[0]); fprintf(stderr, "%s: requires at least one input .hmml file\n", Args[0]);
PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation); PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation);
return 1; return 1;
} }
@ -1331,6 +1330,27 @@ main(int ArgC, char **Args)
{ {
CSSDir[StringLength(CSSDir) - 1] = '\0'; CSSDir[StringLength(CSSDir) - 1] = '\0';
} }
bool ValidDefaultMedium = FALSE;
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
{
if(!StringsDiffer(DefaultMedium, CategoryMedium[i][0]))
{
ValidDefaultMedium = TRUE;
break;
}
}
if(!ValidDefaultMedium)
{
fprintf(stderr, "Specified default medium \"%s\" not available. Valid media are:\n", DefaultMedium);
for(int i = 0; i < ArrayCount(CategoryMedium); ++i)
{
fprintf(stderr, " %s\n", CategoryMedium[i][0]);
}
fprintf(stderr, "To have \"%s\" added to the list, contact matt@handmadedev.org\n", DefaultMedium);
return 1;
}
if(ImagesDir[StringLength(ImagesDir) - 1] == '/') if(ImagesDir[StringLength(ImagesDir) - 1] == '/')
{ {
ImagesDir[StringLength(ImagesDir) - 1] = '\0'; ImagesDir[StringLength(ImagesDir) - 1] = '\0';
@ -1848,12 +1868,6 @@ main(int ArgC, char **Args)
HasQuote = TRUE; HasQuote = TRUE;
// TODO(matt): QUOTE
if(Anno->quote.author)
{
printf("%s\n", Anno->quote.author);
}
if(BuildQuote(&QuoteInfo, Anno->quote.author ? Anno->quote.author : HMML.metadata.stream_username ? HMML.metadata.stream_username : HMML.metadata.member, Anno->quote.id, QuoteDir) == 1) if(BuildQuote(&QuoteInfo, Anno->quote.author ? Anno->quote.author : HMML.metadata.stream_username ? HMML.metadata.stream_username : HMML.metadata.member, Anno->quote.id, QuoteDir) == 1)
{ {
fprintf(stderr, "%s:%d: Quote #%s %d not found! Consider pulling the latest quotes\n", fprintf(stderr, "%s:%d: Quote #%s %d not found! Consider pulling the latest quotes\n",
@ -1915,8 +1929,8 @@ main(int ArgC, char **Args)
if(!HasMedium) if(!HasMedium)
{ {
BuildFilter(TopicsArray, &UniqueTopics, MediaArray, &UniqueMedia, "default"); BuildFilter(TopicsArray, &UniqueTopics, MediaArray, &UniqueMedia, DefaultMedium);
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, "default"); BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, DefaultMedium);
} }
CopyStringToBuffer(&AnnotationClass, "\""); CopyStringToBuffer(&AnnotationClass, "\"");
@ -2583,6 +2597,10 @@ main(int ArgC, char **Args)
"{\n" "{\n"
" setDotLightness(topicDots[i]);\n" " setDotLightness(topicDots[i]);\n"
"}\n" "}\n"
"\n"
"if(location.hash) {\n"
" player.setTime(location.hash.startsWith('#') ? location.hash.substr(1) : location.hash);\n"
"}\n"
" </script>"); " </script>");
#if DEBUG #if DEBUG