Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions example/finisher/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Build output
/website_build

# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
30 changes: 30 additions & 0 deletions example/finisher/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.

include: package:lints/recommended.yaml

# Uncomment the following section to specify additional rules.

# linter:
# rules:
# - camel_case_types

# analyzer:
# exclude:
# - path/to/excluded/files/**

# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints

# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
29 changes: 29 additions & 0 deletions example/finisher/bin/finisher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import 'dart:async';

import 'package:static_shock/static_shock.dart';

Future<void> main(List<String> arguments) async {
final staticShock = StaticShock()
..plugin(const MarkdownPlugin())
..finish(PickedPagesFinisher(picker: DirectoryPicker.parse("posts")));

// Generate the static website.
await staticShock.generateSite();
}

class PickedPagesFinisher implements Finisher {
final Picker picker;
const PickedPagesFinisher({required this.picker});

@override
FutureOr<void> execute(StaticShockPipelineContext context) {
// a finisher is called after the site is generated and the index containing the picked pages is produced.
// here we're using that index along with a picker to filter the pages in the index to just those filtered by the
// picker. this is the base of what an RSS or ATOM generator would do, i.e. filter some set of generated pages in
// the site to produce an RSS or ATOM feed.
print("Picked Pages:");
for (final page in context.pagesIndex.pages) {
if (picker.shouldPick(page.sourcePath)) print(page);
}
}
}
8 changes: 8 additions & 0 deletions example/finisher/build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Hello, world!</h1>
<p>This title and paragraph were written in Markdown. Then, they were converted into HTML, and inserted
into a Jinja template layout for this page.</p>
<h1>Posts</h1>
<ul>
<li><a href="posts/post1/">post 1</a></li>
<li><a href="posts/post2/">post 2</a></li>
</ul>
2 changes: 2 additions & 0 deletions example/finisher/build/posts/post1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>post 1</h1>
<p>this is post 1</p>
2 changes: 2 additions & 0 deletions example/finisher/build/posts/post2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>post 2</h1>
<p>this is post 2</p>
Loading