Skip to content
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

No images in excerpt #207

Open
afilipek3 opened this issue Aug 10, 2015 · 3 comments
Open

No images in excerpt #207

afilipek3 opened this issue Aug 10, 2015 · 3 comments

Comments

@afilipek3
Copy link

First of all thank you for making such a compact, easy blog! I've been trying to put a preview image in the excerpt section but it just pastes it into the body of the post instead. I'm not sure if this is an issue exactly, but is there anyway to have images on the preview part of the posts where it usually just shows the excerpt?

@kershnerd
Copy link

I also need this... There should be an optional intro image property on the Post Model. I have tried to figure this out, but it is beyond me.

@m1kjay
Copy link

m1kjay commented Feb 8, 2016

I don't know if this is helpful at all, but I ran into this issue and added a helper function to post.cshtml to get the source of the first image in the post. Invoked using @MarkupHelper.GetPic(Model.Content):

@functions{
    public class MarkupHelper
    {

    public static System.Xml.XPath.XPathDocument GetDoc(string markup)
    {
    try
    {
    StringReader stringReader = new StringReader(markup);
    System.Xml.XPath.XPathDocument xPathdocument;
    using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(stringReader,
    new System.Xml.XmlReaderSettings() { ConformanceLevel = System.Xml.ConformanceLevel.Fragment }))
    {
    xPathdocument = new System.Xml.XPath.XPathDocument(xmlReader);
    }
    return xPathdocument;
    }
    catch
    {
    System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create(new StringReader(""));
    return new System.Xml.XPath.XPathDocument(xmlReader);
    }
    }

    public static string GetPic(string markup)
    {

    System.Xml.XPath.XPathNavigator nav = GetDoc(markup).CreateNavigator();
    System.Xml.XPath.XPathNavigator node = nav.SelectSingleNode("//img/@src");

    return node == null ? "" : node.Value;
    }
    }
    }

@write2akhilr
Copy link

write2akhilr commented Oct 12, 2016

@m1kjay This is awesome, I was figuring on server side how to extract single image to use in OffCanvas theme.
My bit if there is no image found then don't show blank image icon at all:

@if(string.IsNullOrWhiteSpace(MarkupHelper.GetPic(Model.Content))!=null && MarkupHelper.GetPic(Model.Content).ToString()!="")
{
<img [email protected](Model.Content) />
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants