Example #1
0
        public override void Init()
        {
            _minWidth  = int.Parse(Config["minWidth"]);
            _minHeight = int.Parse(Config["minHeight"]);
            _maxWidth  = int.Parse(Config["maxWidth"]);

            _client = new S3Util(Config["awsKey"], Config["awsSecret"], Config["awsRegion"])
            {
                Log = Log
            };
        }
Example #2
0
        public override void Init()
        {
            _bucket = Config["bucket"];
            var theme = Config["theme"];

            _postsPerPage = int.Parse(Config["postsPerPage"]);

            if (string.IsNullOrEmpty(theme))
            {
                throw new ArgumentException("No theme was specified");
            }

            Handlebars.RegisterHelper("tz_created",
                                      (writer, context, parameters) =>
            {
                var date = (DateTime)context.Created;
                var tz   = Config["tz"];
                if (!string.IsNullOrEmpty(tz))
                {
                    var tzinfo = TimeZoneInfo.FindSystemTimeZoneById(tz);
                    if (tzinfo != null)
                    {
                        date = TimeZoneInfo.ConvertTimeFromUtc(date, tzinfo);
                    }
                }
                writer.WriteSafeString(date);
            });

            Handlebars.RegisterHelper("xml_created",
                                      (writer, context, parameters) =>
            {
                var date = (DateTime)context.Created;
                writer.WriteSafeString(date.ToString("o"));
            });

            Handlebars.RegisterHelper("encode",
                                      (writer, context, parameters) =>
            {
                if (parameters.Length != 1)
                {
                    throw new ArgumentException("escape helper must have exactly one argument");
                }

                writer.WriteSafeString(WebUtility.HtmlEncode((string)parameters[0]));
            });

            var themePath = Path.Combine(_basePath, theme);

            _assetPath = Path.Combine(themePath, "assets");

            var header = Path.Combine(themePath, "header.hbs");

            if (File.Exists(header))
            {
                using (var reader = new StreamReader(File.OpenRead(header)))
                {
                    var template = Handlebars.Compile(reader);
                    Handlebars.RegisterTemplate("header", template);
                }
            }

            var footer = Path.Combine(themePath, "footer.hbs");

            if (File.Exists(footer))
            {
                using (var reader = new StreamReader(File.OpenRead(footer)))
                {
                    var template = Handlebars.Compile(reader);
                    Handlebars.RegisterTemplate("footer", template);
                }
            }

            var index = Path.Combine(themePath, "index.hbs");

            if (!File.Exists(index))
            {
                throw new FileNotFoundException("Could not find index template", index);
            }
            _index = Handlebars.Compile(File.ReadAllText(index));

            var post = Path.Combine(themePath, "post.hbs");

            if (File.Exists(post))
            {
                _post = Handlebars.Compile(File.ReadAllText(post));
            }
            else
            {
                Log.Info("Post template not found, post pages will not be generated.");
            }

            var feed = Path.Combine(themePath, "feed.hbs");

            if (File.Exists(feed))
            {
                _feed = Handlebars.Compile(File.ReadAllText(feed));
            }
            else
            {
                Log.Info("Feed template not found, rss feed will not be generated.");
            }

            _client = new S3Util(Config["awsKey"], Config["awsSecret"], Config["awsRegion"])
            {
                Log = Log
            };
        }