protected override void Given() { _frontMatter = "title: foo"; _sut = new FrontMatterParser(); _expectedTitle = "foo"; }
public static string GetMimeType(this string path) { var mimeType = "application/octet-stream"; try { var extension = Path.GetExtension(path); extension = extension.ToLower(); switch (extension) { case ".jpg": case ".jpeg": mimeType = "image/jpg"; break; case ".gif": mimeType = "image/gif"; break; case ".png": mimeType = "image/png"; break; case ".ico": mimeType = "image/x-icon"; break; case ".css": mimeType = "text/css"; break; case ".js": mimeType = "text/javascript"; break; case ".htm": case ".html": mimeType = "text/html"; break; case ".txt": mimeType = "text/plain"; break; default: if (FrontMatterParser.IsFrontMatterExtension(extension)) { mimeType = "text/plain"; } break; } } catch { } return(mimeType); }
private void LoadInclude(string includeRelPath, Site site) { IMetadata data; string rawContent; var path = GetPath(includeRelPath); FrontMatterParser.Parse(System.IO.File.ReadAllText(path), out rawContent, out data); var name = Path.GetFileNameWithoutExtension(path); site.Includes.Add(new TemplateMock(name, rawContent, data)); }
private void ParseTextFile(IFile src, out string rawContent, out IMetadata data, out string layoutName) { try { FrontMatterParser.Parse(src.AsTextContent(), out rawContent, out data); layoutName = data.GetRemoveParameterOrDefault <string>(LAYOUT_VAR_NAME); } catch (Exception ex) { throw new UserMessageException($"Failed to deserialize the metadata from the '{src.Location.ToPath()}'", ex); } }
protected override void Given() { var title = "This is the title"; var summary = "This is the summary"; var tags = "[tag1,tag2 , tag3,tag4]"; var author = "Sasw"; var languageCode = "ES"; var image = "sample.png"; var publishedOn = "2020-01-09"; var basePath = "https://foo/bar"; _frontMatter = $"title: {title}\n" + $"summary: {summary}\n" + $"tags: {tags}\n" + $"author: {author}\n" + $"languageCode: {languageCode}\n" + $"image: {image}\n" + $"publishedOn: {publishedOn}\n" + $"basePath: {basePath}\n" + "foo: irrelevant"; _sut = new FrontMatterParser(); _expectedTitle = title; _expectedSummary = summary; _expectedAuthor = author; _expectedLanguageCode = languageCode; _expectedTags = tags .Replace("[", string.Empty) .Replace("]", string.Empty) .Split(",") .Select(x => x.Trim()); _expectedImage = image; _expectedPublishedOn = new DateTime(2020, 1, 9); _expectedBasePath = basePath; }
protected override void Given() { _frontMatter = ""; _sut = new FrontMatterParser(); }