aboutsummaryrefslogtreecommitdiffstats
path: root/src/directives.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/directives.c')
-rw-r--r--src/directives.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/directives.c b/src/directives.c
new file mode 100644
index 0000000..65d2e7b
--- /dev/null
+++ b/src/directives.c
@@ -0,0 +1,62 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <string.h>
+
+#include "directives.h"
+#include "error.h"
+#include "utils.h"
+
+
+const static blogc_directive_t registry[] = {
+ {"youtube", blogc_directive_youtube},
+ {NULL, NULL},
+};
+
+
+char*
+blogc_directive_loader(blogc_directive_ctx_t *ctx, blogc_error_t **err)
+{
+ if (ctx == NULL)
+ return NULL;
+ if (err == NULL || *err != NULL)
+ return NULL;
+ for (unsigned int i = 0; registry[i].name != NULL; i++)
+ if (0 == strcmp(ctx->name, registry[i].name))
+ return registry[i].callback(ctx, err);
+ *err = blogc_error_new_printf(BLOGC_WARNING_CONTENT_PARSER,
+ "Directive not found: %s", ctx->name);
+ return NULL;
+}
+
+
+static char*
+blogc_directive_youtube(blogc_directive_ctx_t *ctx, blogc_error_t **err)
+{
+ if (ctx->argument == NULL) {
+ *err = blogc_error_new_printf(BLOGC_WARNING_CONTENT_PARSER,
+ "youtube: video ID must be provided as argument");
+ return NULL;
+ }
+
+ char *width = sb_trie_lookup(ctx->params, "width");
+ char *height = sb_trie_lookup(ctx->params, "height");
+
+ // using default 16:9 sizes provided by youtube as of 2015-11-04
+ return sb_strdup_printf(
+ "<iframe width=\"%s\" height=\"%s\" "
+ "src=\"https://www.youtube.com/embed/%s\" frameborder=\"0\" "
+ "allowfullscreen></iframe>%s",
+ width == NULL ? "560" : width,
+ height == NULL ? "315" : height,
+ ctx->argument, ctx->eol);
+}