-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 241 #248
base: master
Are you sure you want to change the base?
Issue 241 #248
Changes from 3 commits
bce7580
07a18f9
2cae450
2a0a90a
b7d136a
09fbf22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.bundle/ | ||
.jekyll-cache/ | ||
.sass-cache/ | ||
src/_data/code.json | ||
public/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
layout: default | ||
main: | ||
class: usa-grid usa-section usa-content usa-layout-docs | ||
--- | ||
|
||
<div class="usa-grid usa-section"> | ||
<div class="usa-layout-docs-main_content"> | ||
<header> | ||
{%- if page.title -%} | ||
<h1>{{ page.title }}</h1> | ||
|
||
{%- if page.date.created -%} | ||
<small class="usa-font-lead">Last updated <time datetime="{{ page.date.lastModified }}">{{ page.date.lastModified | date_to_string: 'ordinal', 'US' }}</time></small> | ||
{%- endif -%} | ||
{%- endif -%} | ||
</header> | ||
|
||
<p> | ||
{{ page.description }} | ||
</p> | ||
<p>Status: {{ page.status }}</p> | ||
<p>Organization: {{ page.organization }}</p> | ||
<p>Source: <a href="{{ page.repositoryURL }}">{{ page.repositoryURL }}</a></p> | ||
<p>License: <a href="{{ page.permissions.licenses[0].URL }}">{{ page.permissions.licenses[0].name }}</a></p> | ||
<p>Contact: <a href="mailto://{{ page.contact.email }}">{% if page.contact.name %} {{ page.contact.name }} {% else %} email {% endif %}</a></p> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are situations in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Enhanced it with a couple of checks as there is some pollution in the data There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I meant at the end... it says {% if page.contact.name %} {{ page.contact.name }} {% else %} {{page.contact.email}} {% endif %} Just a thought. I guess I'm open to either just the word "email" or the actual email... |
||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## | ||
# | ||
# This module will generate an code.json file inside the src/_data directory | ||
# BEFORE the site is generated. The code.json can therefor be used inside | ||
# page templating syntax by using the variables | ||
# `data.code.<properties>` | ||
# | ||
## | ||
|
||
module RunMeOnce | ||
milovanderlinden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def self.process(site, payload) | ||
return if @processed | ||
input_dir ||= File.expand_path('../_releases', __dir__) | ||
file_paths ||= Dir.glob(File.join(input_dir, '**', '*.json')).sort | ||
output = { | ||
agency: 'DOD', | ||
version: '2.0.0', | ||
measurementType: { | ||
method: 'projects' | ||
}, | ||
releases: [] | ||
} | ||
|
||
file_paths.each do |file_path| | ||
output[:releases] << JSON.parse(File.read(file_path)) | ||
end | ||
|
||
path = 'src/_data/code.json' | ||
FileUtils.mkdir_p(File.dirname(path)) | ||
File.open(path, 'w') do |f| | ||
f.write(JSON.pretty_generate(output)) | ||
end | ||
@processed = true | ||
end | ||
end | ||
|
||
Jekyll::Hooks.register :site, :after_init do |site, payload| | ||
RunMeOnce.process(site, payload) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
# coding: utf-8 | ||
# Generate pages from individual records in yml files | ||
# (c) 2014-2016 Adolfo Villafiorita | ||
# Distributed under the conditions of the MIT License | ||
|
||
module Jekyll | ||
|
||
module Sanitizer | ||
# strip characters and whitespace to create valid filenames, also lowercase | ||
def sanitize_filename(name) | ||
if(name.is_a? Integer) | ||
return name.to_s | ||
end | ||
return name.tr( | ||
"ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÑñÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž", | ||
"AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz" | ||
).downcase.strip.gsub(' ', '-').gsub(/[^\w.-]/, '') | ||
end | ||
end | ||
|
||
# this class is used to tell Jekyll to generate a page | ||
class DataPage < Jekyll::Page | ||
milovanderlinden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
include Sanitizer | ||
|
||
# - site and base are copied from other plugins: to be honest, I am not sure what they do | ||
# | ||
# - `index_files` specifies if we want to generate named folders (true) or not (false) | ||
# - `dir` is the default output directory | ||
# - `data` is the data defined in `_data.yml` of the record for which we are generating a page | ||
# - `name` is the key in `data` which determines the output filename | ||
# - `template` is the name of the template for generating the page | ||
# - `extension` is the extension for the generated file | ||
def initialize(site, base, index_files, dir, data, name, template, extension) | ||
@site = site | ||
@base = base | ||
|
||
# @dir is the directory where we want to output the page | ||
# @name is the name of the page to generate | ||
# | ||
# the value of these variables changes according to whether we | ||
# want to generate named folders or not | ||
if data[name] == nil | ||
puts "error (datapage_gen). empty value for field '#{name}' in record #{data}" | ||
else | ||
filename = sanitize_filename(data[name]).to_s | ||
|
||
@dir = dir + (index_files ? "/" + filename + "/" : "") | ||
@name = (index_files ? "index" : filename) + "." + extension.to_s | ||
|
||
self.process(@name) | ||
self.read_yaml(File.join(base, '_layouts'), template + ".html") | ||
self.data['title'] = data[name] | ||
# add all the information defined in _data for the current record to the | ||
# current page (so that we can access it with liquid tags) | ||
self.data.merge!(data) | ||
end | ||
end | ||
end | ||
|
||
class DataPagesGenerator < Jekyll::Generator | ||
safe true | ||
|
||
# generate loops over _config.yml/page_gen invoking the DataPage | ||
# constructor for each record for which we want to generate a page | ||
|
||
def generate(site) | ||
# page_gen_dirs determines whether we want to generate index pages | ||
# (name/index.html) or standard files (name.html). This information | ||
# is passed to the DataPage constructor, which sets the @dir variable | ||
# as required by this directive | ||
index_files = site.config['page_gen-dirs'] == true | ||
|
||
# data contains the specification of the data for which we want to generate | ||
# the pages (look at the README file for its specification) | ||
data = site.config['page_gen'] | ||
if data | ||
data.each do |data_spec| | ||
index_files_for_this_data = data_spec['index_files'] != nil ? data_spec['index_files'] : index_files | ||
template = data_spec['template'] || data_spec['data'] | ||
name = data_spec['name'] | ||
dir = data_spec['dir'] || data_spec['data'] | ||
extension = data_spec['extension'] || "html" | ||
|
||
if site.layouts.key? template | ||
# records is the list of records defined in _data.yml | ||
# for which we want to generate different pages | ||
records = nil | ||
data_spec['data'].split('.').each do |level| | ||
if records.nil? | ||
records = site.data[level] | ||
else | ||
records = records[level] | ||
end | ||
end | ||
|
||
# apply filtering conditions: | ||
# - filter requires the name of a boolean field | ||
# - filter_condition evals a ruby expression | ||
records = records.select { |r| r[data_spec['filter']] } if data_spec['filter'] | ||
records = records.select { |record| eval(data_spec['filter_condition']) } if data_spec['filter_condition'] | ||
|
||
records.each do |record| | ||
site.pages << DataPage.new(site, site.source, index_files_for_this_data, dir, record, name, template, extension) | ||
end | ||
else | ||
puts "error (datapage_gen). could not find template #{template}" if not site.layouts.key? template | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
module DataPageLinkGenerator | ||
include Sanitizer | ||
|
||
# use it like this: {{input | datapage_url: dir}} | ||
# to generate a link to a data_page. | ||
# | ||
# the filter is smart enough to generate different link styles | ||
# according to the data_page-dirs directive ... | ||
# | ||
# ... however, the filter is not smart enough to support different | ||
# extensions for filenames. | ||
# | ||
# Thus, if you use the `extension` feature of this plugin, you | ||
# need to generate the links by hand | ||
def datapage_url(input, dir) | ||
extension = Jekyll.configuration({})['page_gen-dirs'] ? '/' : '.html' | ||
"#{dir}/#{sanitize_filename(input)}#{extension}" | ||
end | ||
end | ||
|
||
end | ||
|
||
Liquid::Template.register_filter(Jekyll::DataPageLinkGenerator) | ||
Jekyll::Hooks.register :site, :after_init do |site, payload| | ||
RunMeOnce.process(site, payload) | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: Projects | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a good start, but I'd like to see a bit more style and layout on this page before we push it. Maybe add a couple more details to this list? Perhaps we could steal the layout/styles of the Code.gov browser projects page? |
||
layout: page | ||
--- | ||
|
||
<div class="usa-layout-docs-main_content" markdown="1"> | ||
|
||
This is an incomplete list of projects that are available as open source. | ||
|
||
{% for project in site.data.code.releases %} | ||
* [{{ project.name}}](/projects{{project.name | datapage_url: dir}}); {{ project.description}} | ||
milovanderlinden marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{% endfor %} | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, thinking this might be a
<ul>
? They're not really paragraphs :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am open to all suggestions. If you are sure you want me to change it to
I will.