{layout='layouts/_blog-layout'}

{!--
	Redirect
	============
	This is a blog single entry page, it'll never need a fourth segment, so we use the following code to make sure the page redirects if someone types in an incorrect URL in the browser address bar, by adding new segments. i.e. http://example.com/blog/entry/title/nothing
--}
{if segment_4}
	{redirect='{segment_1}/{segment_2}/{segment_3}'}
{/if}

{!-- page vars (prefix p_) --}
{preload_replace:p_title='My Blog'}
{preload_replace:p_description='A blog about things, things I like and things I do.'}
{preload_replace:p_url='blog'}
{preload_replace:p_url_entry='entry'}
{!-- channel vars (prefix ch_) --}
{preload_replace:ch='blog'}
{preload_replace:ch_disable='category_fields|member_data|pagination'}
{!-- layout vars, channel/page related --}
{layout:set name='ch' value='{ch}'}
{layout:set name='p_url' value='{p_url}'}
{layout:set name='p_title' value='{p_title}'}


		{!-- single-entry pagination --}
		<div class="paginate single">
			{exp:channel:prev_entry channel='{ch}'}
				<a class="page-prev" href="{path='{p_url}/{p_url_entry}'}" title="{title}">Previous</a>
			{/exp:channel:prev_entry}
			{exp:channel:next_entry channel='{ch}'}
				<a class="page-next" href="{path='{p_url}/{p_url_entry}'}" title="{title}">Next</a>
			{/exp:channel:next_entry}
		</div>
		{!-- require_entry makes it so if someone types the wrong URL, they will get a 404 page --}
		{exp:channel:entries channel='{ch}' disable='{ch_disable}' limit='1' require_entry='yes'}
			{!-- layout vars, dynamic, not output --}
			{layout:set name='title' value='{seo_title}{gv_sep}{p_title}{gv_sep}'}
			{layout:set name='description' value='{seo_desc}'}
			{layout:set name='entry_ch' value='{ch}'}
			{!-- OpenGraph meta output --}
			{layout:set name='og_title' value='{seo_title}'}
			{layout:set name='og_url'}{path='{p_url}'}{/layout:set}
			{layout:set name='og_description' value='{seo_desc}'}
			{!-- /layout vars, dynamic, not output --}

			{!-- content output --}
			<h1>{title}</h1>
			{!-- video, youtube or vimeo? (GRID) --}
			{if blog_video}
				{blog_video}
					{if blog_video:type == 'youtube'}
						<figure class="video">
							<div class="player">
								<iframe width="940" height="529" src="http://www.youtube.com/embed/{blog_video:id}?rel=0&controls=2&color=white&autohide=1" frameborder="0" allowfullscreen></iframe>
							</div>
						</figure>
					{/if}
					{if blog_video:type == 'vimeo'}
						<figure class="video">
							<div class="player">
								<iframe src="//player.vimeo.com/video/{blog_video:id}?color=f0a400" width="940" height="529" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
							</div>
						</figure>
					{/if}
				{/blog_video}
			{/if}
			{!-- audio, soundcloud or bandcamp? (GRID) --}
			{if blog_audio}
				{blog_audio}
					{if blog_audio:type == 'soundcloud'}
						<figure class="audio-wrap">
							<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/{blog_audio:id}&amp;color=ff5500&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false"></iframe>
						</figure>
					{/if}
					{if blog_audio:type == 'bandcamp'}
						<figure class="audio-wrap">
							<iframe style="border: 0; width: 100%; height: 120px;" src="http://bandcamp.com/EmbeddedPlayer/album={blog_audio:id}/size=large/bgcol=ffffff/linkcol=0687f5/tracklist=false/artwork=small/transparent=true/" seamless></iframe>
						</figure>
					{/if}
				{/blog_audio}
			{/if}
			{!-- image (GRID) --}
			{if blog_image}
				{blog_image}
					<figure>
						<img src="{blog_image:image}" alt="{blog_image:caption:attr_safe}">
						<figcaption>{blog_image:caption}</figcaption>
					</figure>
				{/blog_image}
			{/if}
			{!-- blog_content is a textarea with HTML output we don't need to wrap this tag with HTML as that is already included in it's output. --}
			{blog_content}
			{!-- /content output --}

			{!--
				no results redirect
				===================
				If the entry doesn't exist, we redirect to 404. This works in tandem with the require_entry='yes' parameter on the channel entries tag.
			--}
			{if no_results}
				{redirect='404'}
			{/if}
			{!--
				comments
				comment:entries and comment:form are independent of channel:entries
				we've put them into a embed here to demonstrate how to get a specific
				display on the front end of the site using allow_comments.
				This would not work without the embed, as these tags would not parse
				inside the channel:entries tag.
			--}
			{if allow_comments}
				{embed='{p_url}/_comments' ch='{ch}'}
			{if:else}
				{if comment_total >= 1}
					{embed='{p_url}/_comments' ch='{ch}'}
				{/if}
				<div class="alert warn no-results">
					{if comment_expiration_date < current_time AND comment_expiration_date != 0}
						<p>{gv_comment_expired}</p>
					{if:else}
						<p>{gv_comment_disabled}</p>
					{/if}
				</div>
			{/if}
		{/exp:channel:entries}
