-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
67668a7
commit cfc7436
Showing
15 changed files
with
257 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:gengen/utilities.dart'; | ||
|
||
class ContentTokenizer { | ||
final RegExp _frontMatterExp = RegExp( | ||
r'^\s*[+-]{3}\s*([\s\S]*?)\s[+-]{3}\s*\n*([\s\S]*)', | ||
dotAll: false); | ||
|
||
Content? parse(String content) { | ||
var matches = _frontMatterExp.firstMatch(content); | ||
if (matches != null && matches.groupCount >= 1) { | ||
var first = matches.group(1); | ||
var second = matches.group(2); | ||
return Content(first, second); | ||
} | ||
|
||
return Content(null, content); | ||
} | ||
} | ||
|
||
Content? toContent(String content) { | ||
var tokenizer = ContentTokenizer(); | ||
var frontMatter = tokenizer.parse(content); | ||
return frontMatter; | ||
} | ||
|
||
class Content { | ||
String? _frontMatter; | ||
String? content; | ||
|
||
Content(this._frontMatter, this.content); | ||
|
||
Map<String, dynamic> get frontMatter => getFrontMatter(_frontMatter ?? ""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:console/console.dart'; | ||
import 'package:gengen/content/content.dart'; | ||
import 'package:gengen/generator/generator.dart'; | ||
import 'package:gengen/generator/handlers.dart'; | ||
import 'package:gengen/generator/shared/handlers.dart'; | ||
import 'package:gengen/models.dart'; | ||
import 'package:gengen/pipeline/pipeline.dart'; | ||
import 'package:gengen/utilities.dart'; | ||
|
||
class PageGenerator extends Generator<Page> { | ||
PageGenerator(String source, Directory? outputDir, | ||
{super.extensions = const ["html", "liquid", "md", "markdown"], | ||
super.ignoreDirs = const ["assets", "posts", "templates", "public"]}) | ||
: super(source: source, destination: outputDir); | ||
|
||
@override | ||
Future<PageGenerator> transform() async { | ||
for (var source in sources) { | ||
var fileContent = await readFile(source); | ||
if (fileContent == null) { | ||
continue; | ||
} | ||
|
||
var content = toContent(fileContent); | ||
if (content == null) { | ||
continue; | ||
} | ||
|
||
var directoryFrontMatter = getDirectoryFrontMatter(source) ?? {}; | ||
|
||
directoryFrontMatter.addAll({"permalink": PermalinkStructure.post}); | ||
|
||
var page = Page.fromYaml(content.frontMatter, source, | ||
content.content ?? "", directoryFrontMatter, destination); | ||
|
||
collection.add(page); | ||
} | ||
return this; | ||
} | ||
|
||
@override | ||
Future<Generator<Page>> write() async { | ||
Console.setTextColor(Color.WHITE.id, bright: true); | ||
|
||
for (var item in collection) { | ||
Pipeline<Base> pipeline = Pipeline(item, [LiquidWriter(), HtmlWriter()]); | ||
|
||
pipeline.handle(); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
static Pipeline<Generator> pipeline(PageGenerator generator) { | ||
return Pipeline<Generator>( | ||
generator, [CollectHandler(), TransformHandler(), WriteHandler()]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.