Exemple #1
0
        private void ImportPost(BloggerPost post)
        {
            var header = new
            {
                title      = post.Title,
                date       = post.Published,
                layout     = "post",
                categories = post.Categories,
                tags       = post.Tags
            };

            var yamlHeader  = string.Format("---\r\n{0}---\r\n\r\n", header.ToYaml());
            var postContent = yamlHeader + post.Content;

            string fileName = string.Format(@"{0}-{1}.md", post.Published.ToString("yyyy-MM-dd"), post.Title); //not sure about post name

            foreach (char c in System.IO.Path.GetInvalidFileNameChars())
            {
                fileName = fileName.Replace(c, '_');
            }
            // replace some valid ones too
            fileName = fileName.Replace(' ', '-');
            fileName = fileName.Replace('\u00A0', '-');

            try
            {
                fileSystem.File.WriteAllText(Path.Combine(pathToSite, Path.Combine("_posts", fileName)), postContent);
            }
            catch (Exception e)
            {
                Tracing.Info("Failed to write out {0}", fileName);
                Tracing.Debug(e.Message);
            }
        }
Exemple #2
0
        private void ImportPost(BloggerPost post)
        {
            var header = new
            {
                title = post.Title,
                date = post.Published,
                layout = "post",
                categories = post.Categories,
                tags = post.Tags
            };

            var yamlHeader = string.Format("---\r\n{0}---\r\n\r\n", header.ToYaml());
            var postContent = yamlHeader + post.Content;

            string fileName = string.Format(@"{0}-{1}.md", post.Published.ToString("yyyy-MM-dd"), post.Title); //not sure about post name
            foreach (char c in System.IO.Path.GetInvalidFileNameChars())
            {
                fileName = fileName.Replace(c, '_');
            }
            // replace some valid ones too
            fileName = fileName.Replace(' ', '-'); 
            fileName = fileName.Replace('\u00A0', '-');

            try
            {
                fileSystem.File.WriteAllText(Path.Combine(pathToSite, Path.Combine("_posts", fileName)), postContent);
            }
            catch (Exception e)
            {
                Tracing.Info(String.Format("Failed to write out {0}", fileName));
                Tracing.Debug(e.Message);
            }
        }
Exemple #3
0
        public BloggerPost GetPost(string blogID)
        {
            var result = new BloggerPost();

            using (var wc = new WebClient())
            {
                wc.Encoding = Encoding.UTF8;
                string tmp = wc.DownloadString("https://" + $"www.googleapis.com/blogger/v3/blogs/{blogID}/posts/?key={this.auth.ApiKey}");
                if (!string.IsNullOrWhiteSpace(tmp))
                {
                    result = this.Deserialize <BloggerPost>(tmp);
                }
            }

            return(result);
        }