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
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
exit
#endif
@ -561,15 +561,6 @@ BuildReference(ref_info *ReferencesArray, int RefIdentifier, int UniqueRefs, HMM
if(Ref.publisher) { Mask |= REF_PUBLISHER; }
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)
{
CopyString(ReferencesArray[UniqueRefs].ID, Ref.isbn);
@ -652,16 +643,16 @@ BuildReference(ref_info *ReferencesArray, int RefIdentifier, int UniqueRefs, HMM
char *CategoryMedium[][3] =
{
// medium icon written name
{ "afk", "…" , "Away from Keyboard"}, // TODO(matt): Filter this out by default
{ "authored", "🗪", "Chat Comment"}, // TODO(matt): Conditionally handle Chat vs Guest Comments
{ "blackboard", "🖌", "Blackboard"},
{ "default", "🖮", "Programming"}, // TODO(matt): Potentially make this configurable per project
{ "experience", "🍷", "Experience"},
{ "owl", "🦉", "Owl of Shame"},
{ "rant", "💢", "Rant"},
{ "research", "📖", "Research"},
{ "run", "🏃", "In-Game"}, // TODO(matt): Potentially make this configurable per project
{ "trivia", "🎲", "Trivia"},
{ "afk", "…" , "Away from Keyboard"}, // TODO(matt): Filter this out by default
{ "authored", "🗪", "Chat Comment"}, // TODO(matt): Conditionally handle Chat vs Guest Comments
{ "blackboard", "🖌", "Blackboard"},
{ "experience", "🍷", "Experience"},
{ "owl", "🦉", "Owl of Shame"},
{ "programming", "🖮", "Programming"}, // TODO(matt): Potentially make this configurable per project
{ "rant", "💢", "Rant"},
{ "research", "📖", "Research"},
{ "run", "🏃", "In-Game"}, // TODO(matt): Potentially make this configurable per project
{ "trivia", "🎲", "Trivia"},
};
void
@ -1224,7 +1215,7 @@ ParseConfig(buffer *Buffer, char *Username)
#endif
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"
"\n"
@ -1235,6 +1226,8 @@ PrintUsage(char *BinaryLocation, char *DefaultCSSDir, char *DefaultImagesDir, ch
" Override default images directory (\"%s\")\n"
" -j <JS directory path>\n"
" Override default JS directory (\"%s\")\n"
" -m <default medium>\n"
" Override default default medium (\"%s\")\n"
" -o <output location>\n"
" Override default output location (\"%s\")\n"
" -q <quotes directory path>\n"
@ -1250,7 +1243,7 @@ PrintUsage(char *BinaryLocation, char *DefaultCSSDir, char *DefaultImagesDir, ch
" CINERA_MODE\n"
" =INTEGRATE\n"
" Enable integration\n",
BinaryLocation, DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation);
BinaryLocation, DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation);
}
int
@ -1267,6 +1260,9 @@ main(int ArgC, char **Args)
char *DefaultJSDir = ".";
char *JSDir = DefaultJSDir;
char *DefaultDefaultMedium = "programming";
char *DefaultMedium = DefaultDefaultMedium;
char *DefaultTemplateLocation = "template.html";
char *TemplateLocation = DefaultTemplateLocation;
@ -1283,12 +1279,12 @@ main(int ArgC, char **Args)
if(ArgC < 2)
{
PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation);
PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation);
return 1;
}
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)
{
@ -1301,6 +1297,9 @@ main(int ArgC, char **Args)
case 'j':
JSDir = optarg;
break;
case 'm':
DefaultMedium = optarg;
break;
case 'o':
OutLocation = optarg;
OutIntegratedLocation = optarg;
@ -1315,7 +1314,7 @@ main(int ArgC, char **Args)
// Override config path, once we even have a default!
case 'h':
default:
PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation);
PrintUsage(Args[0], DefaultCSSDir, DefaultImagesDir, DefaultJSDir, DefaultDefaultMedium, DefaultQuoteDir, DefaultOutLocation, DefaultTemplateLocation);
return 1;
}
}
@ -1323,7 +1322,7 @@ main(int ArgC, char **Args)
if(optind == ArgC)
{
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;
}
@ -1331,6 +1330,27 @@ main(int ArgC, char **Args)
{
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] == '/')
{
ImagesDir[StringLength(ImagesDir) - 1] = '\0';
@ -1848,12 +1868,6 @@ main(int ArgC, char **Args)
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)
{
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)
{
BuildFilter(TopicsArray, &UniqueTopics, MediaArray, &UniqueMedia, "default");
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, "default");
BuildFilter(TopicsArray, &UniqueTopics, MediaArray, &UniqueMedia, DefaultMedium);
BuildCategories(&AnnotationClass, &Category, &MarkerIndex, &HasCategory, &HasMedium, DefaultMedium);
}
CopyStringToBuffer(&AnnotationClass, "\"");
@ -2583,6 +2597,10 @@ main(int ArgC, char **Args)
"{\n"
" setDotLightness(topicDots[i]);\n"
"}\n"
"\n"
"if(location.hash) {\n"
" player.setTime(location.hash.startsWith('#') ? location.hash.substr(1) : location.hash);\n"
"}\n"
" </script>");
#if DEBUG