I am using Metalsmith to generate a static site from a markdown file.
The people editing the markdown file will write: {{{link "docs/file.docs"}}} and they expect a link on the site with that file (relative link)
The helper is simple, I tested and it is working:
handlebars.registerHelper('link', function(path) {
var url = handlebars.escapeExpression(path);
return new handlebars.SafeString(
"<a href='" + url + "'>" + url + "</a>"
);
});
But how can I add this helper and use it in my metalsmith configuration?
Here is a summarised example.
index.md:
etc etc link to the page is {{{link "docs/file.doc"}}}
I want with a simple make the following part of the html to be created:
etc etc link to the page is <a href='docs/file.doc'>docs/file.doc</a>
I found the answer here: https://segment.com/blog/building-technical-documentation-with-metalsmith/
Here is my index.js config for Metalsmith:
var Metalsmith = require('metalsmith');
var markdown = require('metalsmith-markdown');
var permalinks = require('metalsmith-permalinks');
var handlebars = require('handlebars');
var inplace = require('metalsmith-in-place');
handlebars.registerHelper('link', function(path) {
var url = handlebars.escapeExpression(path);
return new handlebars.SafeString(
"<a href='" + url + "'>" + url + "</a>"
);
});
Metalsmith(__dirname)
.metadata({ title: "Static Site" })
.source('./src')
.destination('/var/www')
.use(inplace({ engine: 'handlebars', pattern: '**/*.md' }))
.use(markdown())
.build(function(err, files) {
if (err) { throw err; }
});
Related
This is my code so far, It downloads a small 240px image. Can I get the full sized pic to create a lightbox?
<script>
jQuery(function(){
var apikey = 'xxxxx';
var userid = 'xxxx';
jQuery.getJSON('https://api.flickr.com/services/rest/?&method=flickr.people.getPublicPhotos&api_key='+apikey+'&user_id='+userid+'&format=json&jsoncallback=?',
function(data){
jQuery.each(data.photos.photo, function(i,item){
var purl = 'http://farm' + item.farm + '.static.flickr.com/' + item.server + '/' + item.id + '_' + item.secret + '_m.jpg';
var pid = item.id;
var container = '<img src='+ purl+' />';
console.log(container);
jQuery(container).appendTo('#images');
});
});
});
</script>
Sure thing! You can use the API flickr.photos.getSizes to get a list of all the sizes available. Make one Ajax call to flickr.photos.getSizes, pick the largest one from that list, and then make your Ajax call for its URL (you won't have to stitch the URL together as you do in your original code).
I'm using the following to load posts into a index page of a wordpress site. The problem is when it gets to the last page and there are no more posts to load. Its just keeps reloading the last page.
Any ideas of how I might stop this from happening? Thanks.
var $content = '#content';
var $nav_wrap = '.navigation';
var $anchor = '.navigation a.next';
var $text = 'Load More';
var $next_href = $($anchor).attr('href'); // Get URL for the next set of posts
$($nav_wrap).html('<a id="almc-load-more" href="' + $next_href + '">' + $text + '</a>');
$('#almc-load-more').click(function(e) {
e.preventDefault();
$.get($(this).attr('href'), '', function(data) {
var $timestamp = new Date().getTime();
var $new_content = $($content, data).wrapInner('<div class="almc-loaded" id="almc-' + $timestamp + '" />').html(); // Grab just the content
$next_href = $($anchor, data).attr('href'); // Get the new href
$('html,body').animate({scrollTop: $($nav_wrap).position().top}, 'slow'); // Animate scroll
$($nav_wrap).before($new_content); // Append the new content
$('#almc-' + $timestamp).hide().fadeIn('slow'); // Animate load
$('#almc-load-more').attr('href', $next_href); // Change the next URL
$('.almc-loaded ' + $nav_wrap).remove(); // Remove the original navigation
});
});
Above code taken from here: http://kaspars.net/blog/wordpress/jquery-script-for-loading-more-posts
You could add some code to check if the new href is different than the current href, and then only try to add a new post if they're different. Then, if they aren't, you could have a message saying there are no more posts.
var lastLink;
$('#almc-load-more').click(function(e) {
if ( $anchor == $('.navigation a.next').last() ) {
lastLink = 1;
}
if (lastLink == 1) {return} else {
...
}
...
After the comment from Mr. Mayers (Thanks) I gave up on the code and used this tutorial:
http://www.problogdesign.com/wordpress/load-next-wordpress-posts-with-ajax/
Has / does everything I needed.
i have add export functionality in my application. It's work very well. Now i want to add auto download functionality after completion of Export function.
using c# asp.net
You can achieve this by: string file = "";
file = "Path of File Name to Download";
if (file != "")
{
context.Response.Clear();
context.Response.ContentType = "application/octet-stream";
context.Response.AddHeader("content-disposition", "attachment;filename=" + Path.GetFileName(file));
context.Response.WriteFile(file);
context.Response.End();
}
add this script.
<script type="text/javascript">
function populateIframe(id,path)
{
var ifrm = document.getElementById(id);
ifrm.src = "download.php?path="+path;
}
</script>
Place this where you want the download button(here we use just a link):
<iframe id="frame1" style="display:none"></iframe>
download
The file 'download.php' (needs to be put on your server) simply contains:
<?php
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=".$_GET['path']);
readfile($_GET['path']);
?>
I would like to create a handlebars template and use a local helper for just that single template. I know how to use Handlebars.registerHelper to register helpers for all templates, but I only need this for the local template. (something similar to what ExtJS supports with XTemplates)
For example something like this based upon handlebars.js documentation:
var context = { posts: [{url: "/hello-world", body: "Hello World!"}] };
var source = "<ul>{{#posts}}<li>{{{link_to this}}}</li>{{/posts}}</ul>"
var template = Handlebars.compile(source, {
link_to: function(context) {
return "<a href='" + context.url + "'>" + context.body + "</a>";
}
);
template(context);
Is this possible or do all helpers have to be registered globally?
Use this syntax:
template(context, {helpers: helpers})
Local helpers redefine global. So if you want each, if or other registered global helpers just extend object:
helpers = $.extend({}, Handlebars.helpers, helpers);
template(context, {helpers: helpers})
I try do dynamic gallery with jCarousel and Ajax.
My thumbs are loading from '.txt' file.
I try do something like this: If click the thumb body background are change <--- this action for all thumbs but different backgrounds...
But if I try add dynamic url for differents files, it isin't work, If I change + url + for accurate path it work, all picture loaded this same picture from the path - it is understandable ....
below my code
function mycarousel_getItemHTML(url)
{
return '<img src="' + url + '" width="200" height="75" alt="" border="0" class="newbg" />';
};
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({
scroll: 2,
itemLoadCallback: mycarousel_itemLoadCallback
});
$('.newbg').live("click", function(){
$('body').css('background-image', 'url(' + url + ')');
});
});
anybody has an idea as change this code for correct effects...?
I add something like this:
$('.newbg').livequery("click", function(){
var url = $(this).attr("src").replace("_t", "");
var img = new Image();
img.onload = function() {
};
img.src = url;
$('body').css('background-image', 'url(' + url + ')');
});
And it's work correct, thank...
Question can be close...