Example #1
0
        public IBarelyView Index()
        {
            var c = BlogEntryData.All().Find(Query.EQ("Publish", true)).SetSortOrder(SortBy.Descending("Posted"));

            c = c.SetLimit(Config.PageSize);
            var entries = new List <BlogEntryData>();

            foreach (var e in c)
            {
                string text = BetterCache.Get <string>(e.ID.ToString());
                if (text == null)
                {
                    e.Text = Config.GetMarkdown().Transform(e.Text);
                    BetterCache.Add(e.ID.ToString(), e.Text);
                }
                else
                {
                    e.Text = text;
                }

                entries.Add(e);
            }
            var v = new BlogIndexView();

            v.ShowPaging = true;
            v.Page       = 1;
            v.PageMax    = ((int)c.Count()) / Config.PageSize + 1;
            v.Entries    = entries;

            v.Layout.Active = "home";
            v.Layout.Title  = "Earlz.Net - Programming, Electronics, Hacking, Oh My!";
            return(v);
        }
Example #2
0
        public IBarelyView Index(int page)
        {
            var c = BlogEntryData.All().FindAs <BlogEntryData>(Query.EQ("Publish", true)).SetSortOrder(SortBy.Descending("Posted"));

            page -= 1;           //so that routes start with /blog/1 than /blog/0
            if (page == 0)
            {
                PermanentRedirect("/");
            }
            c = c.SetSkip(page * Config.PageSize).SetLimit(Config.PageSize);
            int pagecount = ((int)c.Count()) / Config.PageSize + 1;       //this takes a total count on the collection, not the query.

            var entries = new List <BlogEntryData>();

            foreach (var e in c)
            {
                string text = BetterCache.Get <string>(e.ID.ToString());
                if (text == null)
                {
                    e.Text = Config.GetMarkdown().Transform(e.Text);
                    BetterCache.Add(e.ID.ToString(), e.Text);
                }
                else
                {
                    e.Text = text;
                }

                entries.Add(e);
            }
            if (entries.Count == 0)
            {
                throw new HttpException(404, "not found");
            }
            var v = new BlogIndexView();

            v.ShowPaging    = true;
            page           += 1;
            v.Page          = page;
            v.PageMax       = pagecount;
            v.Entries       = entries;
            v.Layout.Active = "home";
            v.Layout.Title  = "Archive - Page " + (page) + " of " + (v.PageMax) + " - Earlz.Net";
            return(v);
        }
Example #3
0
        public IBarelyView Tag(string tag, int page)
        {
            var v = new BlogIndexView();

            v.ShowPaging    = true;
            v.Tag           = tag;
            v.Layout.Active = "tags";

            MongoCursor <BlogEntryData> c;

            if (tag == "private-draft")
            {
                c = BlogEntryData.All().Find(Query.In("Tags", new BsonArray(new string[] { tag }))).SetSortOrder(SortBy.Descending(new string[] { "Posted" }));
            }
            else
            {
                //otherwise, filter out the private-draft results
                c = BlogEntryData.All().Find(Query.And(Query.NotIn("Tags", new BsonArray(new string[] { "private-draft" })),
                                                       Query.In("Tags", new BsonArray(new string[] { tag })))).SetSortOrder(SortBy.Descending(new String[] { "Posted" }));
            }
            page -= 1;                                              //so that routes start with /blog/1 than /blog/0
            c     = c.SetSkip(page * Config.PageSize).SetLimit(Config.PageSize);
            int pagecount = ((int)c.Count()) / Config.PageSize + 1; //this takes a total count on the collection, not the query.

            var entries = new List <BlogEntryData>();

            foreach (var e in c)
            {
                e.Text = Config.GetMarkdown().Transform(e.Text);
                entries.Add(e);
            }
            if (entries.Count == 0)
            {
                throw new HttpException(404, "not found");
            }
            page           += 1;
            v.Page          = page;
            v.PageMax       = pagecount;
            v.Entries       = entries;
            v.Layout.Active = "tags";
            v.Layout.Title  = "Posts Tagged '" + tag + "' - Page " + (page) + " of " + (v.PageMax) + " - Earlz.Net";
            return(v);
        }
Example #4
0
        public IBarelyView Tag(string tag, int page)
        {
            var v=new BlogIndexView();
            v.ShowPaging=true;
            v.Tag=tag;
            v.Layout.Active="tags";

            MongoCursor<BlogEntryData> c;
            if(tag=="private-draft")
            {
                c=BlogEntryData.All().Find(Query.In("Tags",new BsonArray(new string[]{tag}))).SetSortOrder(SortBy.Descending(new string[]{"Posted"}));
            }
            else
            {
                //otherwise, filter out the private-draft results
                c=BlogEntryData.All().Find(Query.And(Query.NotIn("Tags", new BsonArray(new string[]{"private-draft"})),
                                                     Query.In("Tags",new BsonArray(new string[]{tag})))).SetSortOrder(SortBy.Descending(new String[]{"Posted"}));
            }
            page-=1; //so that routes start with /blog/1 than /blog/0
            c=c.SetSkip(page*Config.PageSize).SetLimit(Config.PageSize);
            int pagecount=((int)c.Count())/Config.PageSize+1; //this takes a total count on the collection, not the query.

            var entries=new List<BlogEntryData>();
            foreach(var e in c){
                e.Text=Config.GetMarkdown().Transform(e.Text);
                entries.Add(e);
            }
            if(entries.Count==0){
                throw new HttpException(404,"not found");
            }
            page+=1;
            v.Page=page;
            v.PageMax=pagecount;
            v.Entries=entries;
            v.Layout.Active="tags";
            v.Layout.Title="Posts Tagged '"+tag+"' - Page "+(page)+" of "+(v.PageMax)+" - Earlz.Net";
            return v;
        }
Example #5
0
        public IBarelyView Index()
        {
            var c=BlogEntryData.All().Find(Query.EQ("Publish",true)).SetSortOrder(SortBy.Descending("Posted"));
            c=c.SetLimit(Config.PageSize);
            var entries=new List<BlogEntryData>();
            foreach(var e in c){
                string text=BetterCache.Get<string>(e.ID.ToString());
                if(text==null)
                {
                    e.Text=Config.GetMarkdown().Transform(e.Text);
                    BetterCache.Add(e.ID.ToString(), e.Text);
                }
                else
                {
                    e.Text=text;
                }

                entries.Add(e);
            }
            var v=new BlogIndexView();
            v.ShowPaging=true;
            v.Page=1;
            v.PageMax=((int)c.Count())/Config.PageSize+1;
            v.Entries=entries;

            v.Layout.Active="home";
            v.Layout.Title="Earlz.Net - Programming, Electronics, Hacking, Oh My!";
            return v;
        }
Example #6
0
        public IBarelyView Index(int page)
        {
            var c=BlogEntryData.All().FindAs<BlogEntryData>(Query.EQ("Publish",true)).SetSortOrder(SortBy.Descending("Posted"));
            page-=1; //so that routes start with /blog/1 than /blog/0
            if(page==0){
                PermanentRedirect("/");
            }
            c=c.SetSkip(page*Config.PageSize).SetLimit(Config.PageSize);
            int pagecount=((int)c.Count())/Config.PageSize+1; //this takes a total count on the collection, not the query.

            var entries=new List<BlogEntryData>();

            foreach(var e in c){
                string text=BetterCache.Get<string>(e.ID.ToString());
                if(text==null)
                {
                    e.Text=Config.GetMarkdown().Transform(e.Text);
                    BetterCache.Add(e.ID.ToString(), e.Text);
                }
                else
                {
                    e.Text=text;
                }

                entries.Add(e);
            }
            if(entries.Count==0){
                throw new HttpException(404,"not found");
            }
            var v=new BlogIndexView();
            v.ShowPaging=true;
            page+=1;
            v.Page=page;
            v.PageMax=pagecount;
            v.Entries=entries;
            v.Layout.Active="home";
            v.Layout.Title="Archive - Page "+(page)+" of "+(v.PageMax)+" - Earlz.Net";
            return v;
        }