mirror of
https://github.com/there4/markdown-resume.git
synced 2024-12-03 08:59:35 -05:00
Add comments to build script, make command line relative to current path and require resume/ in --source path.
This commit is contained in:
parent
0edf7ef5fa
commit
cea267adac
19
.gitignore
vendored
19
.gitignore
vendored
@ -1,16 +1,3 @@
|
||||
|
||||
output/resume-pdf.html
|
||||
|
||||
assets/templates/default.html
|
||||
|
||||
output/resume.pdf
|
||||
|
||||
output/resume.html
|
||||
|
||||
resume/craig.md
|
||||
|
||||
output/craig-pdf.html
|
||||
|
||||
output/craig.html
|
||||
|
||||
output/craig.pdf
|
||||
resume/_*.md
|
||||
output/*.html
|
||||
output/*.pdf
|
||||
|
10
README.md
10
README.md
@ -12,15 +12,15 @@ Turn a simple Markdown document into an elegant resume.
|
||||
|
||||
## Quickstart
|
||||
|
||||
php ./build/build.php --source sample.md
|
||||
php ./build/build.php --source sample.md --pdf
|
||||
php ./build/build.php --source resume/sample.md
|
||||
php ./build/build.php --source resume/sample.md --pdf
|
||||
|
||||
## Options
|
||||
|
||||
If you want to edit your markdown resume in your editor while watching it
|
||||
update in your browser, run this command:
|
||||
|
||||
watch php ./build/build.php -s sample.md -r
|
||||
watch php ./build/build.php -s resume/sample.md -r
|
||||
|
||||
This makes the build script run periodically, and html document will refresh
|
||||
every two seconds. Open the `./ouput/sample.html` file in your browser, and
|
||||
@ -43,6 +43,8 @@ on descendant and adjacent selectors.
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
The initial inspiration is from the [Sample Resume Template](http://sampleresumetemplate.net/).
|
||||
The initial inspiration is from the [Sample Resume Template][srt].
|
||||
However, no HTML from that project has been used in this. General layout has been reused, and media queries
|
||||
have been added. It's a nice template, and if you are a more comfortable with html than markdown, you should use it.
|
||||
|
||||
[srt]: http://sampleresumetemplate.net/ "A great starting point"
|
||||
|
@ -22,41 +22,41 @@ include_once APPLICATION_BASE_PATH . '/vendor/markdown-extra/markdown.php';
|
||||
include_once APPLICATION_BASE_PATH . '/vendor/lessphp/lessc.inc.php';
|
||||
include_once APPLICATION_BASE_PATH . '/vendor/simpledom/simple_html_dom.php';
|
||||
|
||||
|
||||
use Assetic\Asset\AssetCollection;
|
||||
use Assetic\Asset\FileAsset;
|
||||
use Assetic\Asset\GlobAsset;
|
||||
use Assetic\Filter;
|
||||
|
||||
$shortopts = "";
|
||||
$shortopts .= "s:";
|
||||
$shortopts .= "rp";
|
||||
// Setup the command line options
|
||||
$shortopts
|
||||
= "s:" // source
|
||||
. "r" // refresh
|
||||
. "p"; // pdf output
|
||||
|
||||
$longopts = array(
|
||||
"source:",
|
||||
"refresh",
|
||||
"pdf"
|
||||
);
|
||||
|
||||
$options = getopt($shortopts, $longopts);
|
||||
|
||||
// Combine the options to their shorter names
|
||||
if (empty($options['s']) && !empty($options['source'])) {
|
||||
$options['s'] = $options['source'];
|
||||
}
|
||||
$refresh_dev = isset($options['r']) || isset($options['refresh']);
|
||||
|
||||
if (!isset($options['s'])) {
|
||||
exit('Please specify a source document build.php -s resume.pdf');
|
||||
exit("Please specify a source document: build.php -s resume/resume.pdf\n");
|
||||
}
|
||||
|
||||
$basename = pathinfo($options['s'], PATHINFO_FILENAME);
|
||||
$source = './resume/' . $options['s'];
|
||||
$source = './' . $options['s'];
|
||||
$pdf_source = './output/' . $basename . '-pdf.html';
|
||||
$output = './output/' . $basename . '.html';
|
||||
$pdf_output = './output/' . $basename . '.pdf';
|
||||
|
||||
|
||||
$refresh_dev = isset($options['r']) || isset($options['refresh']);
|
||||
|
||||
$css = new AssetCollection(
|
||||
array(
|
||||
new GlobAsset(APPLICATION_BASE_PATH . '/assets/css/*.css')
|
||||
@ -70,9 +70,10 @@ $style = $css->dump();
|
||||
$template = file_get_contents(APPLICATION_BASE_PATH . '/assets/templates/default.html');
|
||||
$resume = file_get_contents($source);
|
||||
|
||||
$resume = Markdown($resume);
|
||||
$resume = SmartyPants($resume);
|
||||
// Process with Markdown, and then use SmartyPants to clean up punctuation.
|
||||
$resume = SmartyPants(Markdown($resume));
|
||||
|
||||
// We'll construct the title for the html document from the h1 and h2 tags
|
||||
$html = str_get_html($resume);
|
||||
$title = sprintf(
|
||||
'%s | %s',
|
||||
@ -80,6 +81,7 @@ $title = sprintf(
|
||||
$html->find('h2', 0)->innertext
|
||||
);
|
||||
|
||||
// We'll now render the Markdown into an html file with Mustache Templates
|
||||
$m = new Mustache;
|
||||
$rendered = $m->render(
|
||||
$template,
|
||||
@ -91,36 +93,41 @@ $rendered = $m->render(
|
||||
)
|
||||
);
|
||||
|
||||
// Save the fully rendered html to the final destination
|
||||
file_put_contents(
|
||||
$output,
|
||||
$rendered
|
||||
);
|
||||
echo "Wrote html to $output\n";
|
||||
|
||||
// If the user wants to make a pdf file, we'll use wkhtmltopdf to convert
|
||||
// the html document into a nice looking pdf.
|
||||
if (isset($options['pdf'])) {
|
||||
|
||||
$pdf_classed = str_replace(
|
||||
// The pdf needs some extra css rules, and so we'll add them here
|
||||
// to our html document
|
||||
$pdf_classed = str_replace(
|
||||
'body class=""',
|
||||
'body class="pdf"',
|
||||
$rendered
|
||||
);
|
||||
);
|
||||
|
||||
if (isset($options['pdf'])) {
|
||||
// Save the new pdf-ready html to a temp destination
|
||||
file_put_contents(
|
||||
$pdf_source,
|
||||
$pdf_classed
|
||||
);
|
||||
|
||||
// Process the document with wkhtmltopdf
|
||||
exec(
|
||||
'wkhtmltopdf '
|
||||
. $pdf_source .' '
|
||||
. $pdf_output
|
||||
. ' && open ' . $pdf_output
|
||||
);
|
||||
|
||||
// Unlink the temporary file
|
||||
unlink($pdf_source);
|
||||
echo "Wrote pdf to $pdf_output\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* End of file build.php */
|
Loading…
x
Reference in New Issue
Block a user