Beispiel #1
0
    public HtmlString comicHeading(int comicNo, string headingTag = "h1", string dateFormat = "MMMM, d yyyy")//create heading for comic page
    //intialize variables
    {
        string   edit           = "";
        string   publishHeading = "";
        int      pageCount      = 0;
        DateTime publishDate    = Convert.ToDateTime(comicDate(comicNo));

        //load settings, comic list, and comic page xml
        var load      = new Comic();
        var settings  = load.LoadComic("/App_Data/WebcomicX.xml");
        var comicList = load.LoadComic("/content/xml/comics/comic-list.xml");
        var pagesDoc  = load.LoadComic("/content/xml/comics/comic-" + comicNo + ".xml");

        pageCount = pagesDoc.Descendants("Page").Count();
        if (HttpContext.Current.User.Identity.IsAuthenticated)
        {
            //if user is authenticated display edit page link
            edit = " <a class='edit'" + (comicNo != 0 ? "href = '/webcomicx/admin/edit-comic/" + comicNo.ToString() + "' > Edit": "href = '/webcomicx/admin/new-comic/ '> Post Comic") + "</a>";
        }

        //set publishHeading variable with date and author
        if (load.comicAuthor(comicNo) != "")
        {
            publishHeading = "<h5><span>By " + load.comicAuthor(comicNo) + " </span> <time datetime='" + publishDate.ToString("yyyy-MM-d") + "' id='pubDate' itemprop='datePublished' pubdate>" + publishDate.ToString(dateFormat) + "</time></h5>";
        }
        else if (load.PrimaryAuthor().ToString() != "")
        {
            publishHeading = "<h5><span>" + load.PrimaryAuthor(link: true) + "</span> <time datetime='" + publishDate.ToString("yyyy-MM-d") + "' id='pubDate' itemprop='datePublished' pubdate>" + publishDate.ToString(dateFormat) + "</time></h5>";
        }
        else
        {
            publishHeading = "<h5><time datetime='" + publishDate.ToString("yyyy-MM-d") + "' id='pubDate' itemprop='datePublished' pubdate>" + publishDate.ToString(dateFormat) + "</time></h5>";
        }
        //add comic title, and publishHeading to create comic heading
        string comicHeading = "<" + headingTag + " itemprop='headline'>" + load.comicTitle(comicNo) + edit + "</" + headingTag + ">" + publishHeading;

        return(new HtmlString(comicHeading));
    }
Beispiel #2
0
    /// <param name="htmlBefore">Add extra html before the webcomic is renderd.</param>
    /// <param name="htmlAfter">Add extra html after the webcomic is renderd.</param>
    public HtmlString WebComic(int currentComic, string attr = "", Func <dynamic, object> htmlBefore = null, Func <dynamic, object> htmlAfter = null, bool lazyLoad = false)//render webcomic
    //initialize variable
    {
        var    webComic     = "";
        var    webComicHtml = "";
        int    pageNo       = 0;
        string src          = "";

        if (htmlBefore == null)
        {
            htmlBefore = item => new HtmlString(String.Format(""));
        }
        if (htmlAfter == null)
        {
            htmlAfter = item => new HtmlString(String.Format(""));
        }
        //load settings and comic pages xml
        var load     = new Comic();
        var settings = load.LoadComic("/App_Data/WebcomicX.xml");
        var pages    = load.LoadComic("/content/xml/comics/comic-" + (currentComic) + ".xml");

        foreach (var page in pages.Descendants("Page"))
        {
            pageNo++;
            if (load.comicImg(currentComic, pageNo) != "")
            {
                //if the image of  the comic is not empty

                //webcomic page caption
                string caption = "";
                string alt     = "";
                if (load.ComicCopy(currentComic, pageNo).ToString() != "")
                {
                    caption = "<figcaption id='page-" + pageNo + "-caption'>" + load.ComicCopy(currentComic, pageNo) + "</figcaption>";
                }
                if (page.Element("Description").Value != "")
                {
                    alt = page.Element("Description").Value;
                }
                else
                {
                    alt = load.comicTitle(currentComic).ToString() + " page " + pageNo;
                }

                if (lazyLoad && pageNo > 2)
                {
                    src = "data-src='" + load.comicImg(currentComic, pageNo) + "'";
                }
                else
                {
                    src = "src='" + load.comicImg(currentComic, pageNo) + "'";
                }

                //create the image element and set its src
                webComic = "<figure><img " + src + " height='auto' width='auto' alt='" + alt + "' >" + caption + "</figure>";
            }
            else     //use a title instead of a image
            {
                if (load.ComicCopy(currentComic, pageNo).ToString() != "")
                {
                    webComic = "<article><h3>Page " + pageNo + "</h3>" + load.ComicCopy(currentComic, pageNo) + "</article>";
                }
                else
                {
                    webComic = "<div class='comic-placeholder'> <h3>" + load.comicTitle(currentComic) + " Page " + pageNo + "</h3> </div>";
                }
            }

            webComicHtml += "<div id='page-" + pageNo + "' " + attr + ">" + htmlBefore(htmlBefore) + webComic + htmlAfter(htmlAfter) + "</div>";
        }
        if (pageNo <= 0)
        {
            webComicHtml = "<div id='page-" + pageNo + "' " + attr + "> <div class='comic-placeholder'> <h3>" + load.comicTitle(currentComic) + " </h3> </div></div>";
        }
        return(new HtmlString(webComicHtml));
    }