Example #1
0
def get_context(context):
	web_page = frappe._dict(context.doc.as_dict())

	if web_page.slideshow:
		web_page.update(get_slideshow(web_page))

	if web_page.enable_comments:
		web_page.comment_list = frappe.db.sql("""select
			comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Web Page"
			and comment_docname=%s order by creation""", web_page.name, as_dict=1) or []

	web_page.update({
		"style": web_page.css or "",
		"script": web_page.javascript or ""
	})
	web_page.update(context)

	web_page.metatags = {
		"name": web_page.title,
		"description": web_page.description or web_page.main_section[:150]
	}

	image = find_first_image(web_page.main_section)
	if image:
		web_page.metatags["image"] = image


	if not web_page.header:
		web_page.header = web_page.title

	return web_page
Example #2
0
	def get_context(self, context):
		# this is for double precaution. usually it wont reach this code if not published
		if not cint(self.published):
			raise Exception("This blog has not been published yet!")

		# temp fields
		context.full_name = get_fullname(self.owner)
		context.updated = global_date_format(self.published_on)

		if self.blogger:
			context.blogger_info = frappe.get_doc("Blogger", self.blogger).as_dict()
			context.author = self.blogger


		context.content = get_html_content_based_on_type(self, 'content', self.content_type)
		context.description = self.blog_intro or strip_html_tags(context.content[:140])

		context.metatags = {
			"name": self.title,
			"description": context.description,
		}

		image = find_first_image(context.content)
		if image:
			context.metatags["image"] = image

		self.load_comments(context)

		context.category = frappe.db.get_value("Blog Category",
			context.doc.blog_category, ["title", "route"], as_dict=1)
		context.parents = [{"name": _("Home"), "route":"/"},
			{"name": "Blog", "route": "/blog"},
			{"label": context.category.title, "route":context.category.route}]
Example #3
0
	def get_context(self, context):
		# this is for double precaution. usually it wont reach this code if not published
		if not cint(self.published):
			raise Exception, "This blog has not been published yet!"

		# temp fields
		context.full_name = get_fullname(self.owner)
		context.updated = global_date_format(self.published_on)

		if self.blogger:
			context.blogger_info = frappe.get_doc("Blogger", self.blogger).as_dict()

		context.description = self.blog_intro or self.content[:140]

		context.metatags = {
			"name": self.title,
			"description": context.description,
		}

		image = find_first_image(self.content)
		if image:
			context.metatags["image"] = image

		context.categories = frappe.db.sql_list("""select name from
			`tabBlog Category` order by name""")

		context.comment_list = get_comment_list(self.doctype, self.name)

		context.children = get_children()

		return context
Example #4
0
	def get_context(self, context):
		# this is for double precaution. usually it wont reach this code if not published
		if not cint(self.published):
			raise Exception, "This blog has not been published yet!"

		# temp fields
		context.full_name = get_fullname(self.owner)
		context.updated = global_date_format(self.published_on)

		if self.blogger:
			context.blogger_info = frappe.get_doc("Blogger", self.blogger).as_dict()

		context.description = self.blog_intro or self.content[:140]

		context.metatags = {
			"name": self.title,
			"description": context.description,
		}

		if "<!-- markdown -->" in context.content:
			context.content = markdown(context.content)

		image = find_first_image(self.content)
		if image:
			context.metatags["image"] = image

		context.comment_list = get_comment_list(self.doctype, self.name)

		context.children = get_children()

		category = frappe.db.get_value("Blog Category", context.doc.blog_category, ["title", "page_name"], as_dict=1)
		context.parents = [{"title": category.title, "name": "blog/{0}".format(category.page_name)}]
Example #5
0
def get_context(context):
    web_page = frappe._dict(context.doc.as_dict())

    if web_page.slideshow:
        web_page.update(get_slideshow(web_page))

    if web_page.enable_comments:
        web_page.comment_list = frappe.db.sql("""select
			comment, comment_by_fullname, creation
			from `tabComment` where comment_doctype="Web Page"
			and comment_docname=%s order by creation""",
                                              web_page.name,
                                              as_dict=1) or []

    web_page.update({
        "style": web_page.css or "",
        "script": web_page.javascript or ""
    })
    web_page.update(context)

    web_page.metatags = {
        "name": web_page.title,
        "description": web_page.description or web_page.main_section[:150]
    }

    image = find_first_image(web_page.main_section)
    if image:
        web_page.metatags["image"] = image

    if not web_page.header:
        web_page.header = web_page.title

    return web_page
Example #6
0
    def get_context(self, context):
        if context.slideshow:
            context.update(get_slideshow(self))

        if self.enable_comments:
            context.comment_list = get_comment_list(self.doctype, self.name)

        context.update({
            "style": self.css or "",
            "script": self.javascript or ""
        })

        if "<!-- render-jinja -->" in self.main_section:
            context["main_section"] = frappe.render_template(
                self.main_section, {
                    "doc": self,
                    "frappe": frappe
                })
            context["no_cache"] = 1

        context.metatags = {
            "name": self.title,
            "description": self.description or (self.main_section or "")[:150]
        }

        image = find_first_image(self.main_section or "")
        if image:
            context.metatags["image"] = image

        if not context.header:
            context.header = self.title

        return context
Example #7
0
	def get_context(self, context):
		# this is for double precaution. usually it wont reach this code if not published
		if not cint(self.published):
			raise Exception, "This blog has not been published yet!"

		# temp fields
		context.full_name = get_fullname(self.owner)
		context.updated = global_date_format(self.published_on)

		if self.blogger:
			context.blogger_info = frappe.get_doc("Blogger", self.blogger).as_dict()

		context.description = self.blog_intro or self.content[:140]

		context.metatags = {
			"name": self.title,
			"description": context.description,
		}

		image = find_first_image(self.content)
		if image:
			context.metatags["image"] = image

		context.categories = frappe.db.sql_list("""select name from
			`tabBlog Category` order by name""")

		context.comment_list = get_comment_list(self.doctype, self.name)

		return context
Example #8
0
	def get_context(self, context):
		# this is for double precaution. usually it wont reach this code if not published
		if not cint(self.published):
			raise Exception, "This blog has not been published yet!"

		# temp fields
		context.full_name = get_fullname(self.owner)
		context.updated = global_date_format(self.published_on)

		if self.blogger:
			context.blogger_info = frappe.get_doc("Blogger", self.blogger).as_dict()

		context.description = self.blog_intro or self.content[:140]

		context.metatags = {
			"name": self.title,
			"description": context.description,
		}

		if "<!-- markdown -->" in context.content:
			context.content = markdown(context.content)

		image = find_first_image(self.content)
		if image:
			context.metatags["image"] = image

		context.comment_list = get_comment_list(self.doctype, self.name)

		context.children = get_children()

		category = frappe.db.get_value("Blog Category", context.doc.blog_category, ["title", "page_name"], as_dict=1)
		context.parents = [{"title": category.title, "name": "blog/{0}".format(category.page_name)}]
Example #9
0
def get_context(context):
	blog_post = context.doc

	# this is for double precaution. usually it wont reach this code if not published
	if not cint(blog_post.published):
		raise Exception, "This blog has not been published yet!"

	# temp fields
	blog_post.full_name = get_fullname(blog_post.owner)
	blog_post.updated = global_date_format(blog_post.published_on)

	if blog_post.blogger:
		blog_post.blogger_info = frappe.get_doc("Blogger", blog_post.blogger).as_dict()

	blog_post.description = blog_post.blog_intro or blog_post.content[:140]

	blog_post.metatags = {
		"name": blog_post.title,
		"description": blog_post.description,
	}

	image = find_first_image(blog_post.content)
	if image:
		blog_post.metatags["image"] = image

	blog_post.categories = frappe.db.sql_list("select name from `tabBlog Category` order by name")

	blog_post.comment_list = frappe.db.sql("""\
		select comment, comment_by_fullname, creation
		from `tabComment` where comment_doctype="Blog Post"
		and comment_docname=%s order by creation""", (blog_post.name,), as_dict=1) or []

	return blog_post.__dict__
Example #10
0
	def set_metatags(self, context):
		context.metatags = {
			"name": context.title
		}

		image = find_first_image(context.main_section or "")
		if image:
			context.metatags["image"] = image
Example #11
0
def get_blog_list(doctype, txt=None, filters=None, limit_start=0, limit_page_length=20, order_by=None):
	conditions = []
	if filters:
		if filters.blogger:
			conditions.append('t1.blogger="%s"' % frappe.db.escape(filters.blogger))
		if filters.blog_category:
			conditions.append('t1.blog_category="%s"' % frappe.db.escape(filters.blog_category))

	if txt:
		conditions.append('(t1.content like "%{0}%" or t1.title like "%{0}%")'.format(frappe.db.escape(txt)))

	if conditions:
		frappe.local.no_cache = 1

	query = """\
		select
			t1.title, t1.name, t1.blog_category, t1.route, t1.published_on,
				t1.published_on as creation,
				t1.content as content,
				ifnull(t1.blog_intro, t1.content) as intro,
				t2.full_name, t2.avatar, t1.blogger,
				(select count(name) from `tabCommunication`
					where
						communication_type='Comment'
						and comment_type='Comment'
						and reference_doctype='Blog Post'
						and reference_name=t1.name) as comments
		from `tabBlog Post` t1, `tabBlogger` t2
		where ifnull(t1.published,0)=1
		and t1.blogger = t2.name
		%(condition)s
		order by published_on desc, name asc
		limit %(start)s, %(page_len)s""" % {
			"start": limit_start, "page_len": limit_page_length,
				"condition": (" and " + " and ".join(conditions)) if conditions else ""
		}

	posts = frappe.db.sql(query, as_dict=1)

	for post in posts:
		post.cover_image = find_first_image(post.content)
		post.published = global_date_format(post.creation)
		post.content = strip_html_tags(post.content[:340])
		if not post.comments:
			post.comment_text = _('No comments yet')
		elif post.comments==1:
			post.comment_text = _('1 comment')
		else:
			post.comment_text = _('{0} comments').format(str(post.comments))

		post.avatar = post.avatar or ""
		post.category = frappe.db.get_value('Blog Category', post.blog_category,
			['route', 'title'], as_dict=True)

		if post.avatar and (not "http:" in post.avatar and not "https:" in post.avatar) and not post.avatar.startswith("/"):
			post.avatar = "/" + post.avatar

	return posts
Example #12
0
	def set_metatags(self, context):
		context.metatags = {
			"name": context.title,
			"description": (context.description or "").replace("\n", " ")[:500]
		}

		image = find_first_image(context.main_section or "")
		if image:
			context.metatags["image"] = image
Example #13
0
def get_blog_list(doctype, txt=None, filters=None, limit_start=0, limit_page_length=20, order_by=None):
	conditions = []
	if filters:
		if filters.blogger:
			conditions.append('t1.blogger=%s' % frappe.db.escape(filters.blogger))
		if filters.blog_category:
			conditions.append('t1.blog_category=%s' % frappe.db.escape(filters.blog_category))

	if txt:
		conditions.append('(t1.content like {0} or t1.title like {0}")'.format(frappe.db.escape('%' + txt + '%')))

	if conditions:
		frappe.local.no_cache = 1

	query = """\
		select
			t1.title, t1.name, t1.blog_category, t1.route, t1.published_on,
				t1.published_on as creation,
				t1.content as content,
				ifnull(t1.blog_intro, t1.content) as intro,
				t2.full_name, t2.avatar, t1.blogger,
				(select count(name) from `tabComment`
					where
						and comment_type='Comment'
						and reference_doctype='Blog Post'
						and reference_name=t1.name) as comments
		from `tabBlog Post` t1, `tabBlogger` t2
		where ifnull(t1.published,0)=1
		and t1.blogger = t2.name
		%(condition)s
		order by published_on desc, name asc
		limit %(start)s, %(page_len)s""" % {
			"start": limit_start, "page_len": limit_page_length,
				"condition": (" and " + " and ".join(conditions)) if conditions else ""
		}

	posts = frappe.db.sql(query, as_dict=1)

	for post in posts:
		post.cover_image = find_first_image(post.content)
		post.published = global_date_format(post.creation)
		post.content = strip_html_tags(post.content[:340])
		if not post.comments:
			post.comment_text = _('No comments yet')
		elif post.comments==1:
			post.comment_text = _('1 comment')
		else:
			post.comment_text = _('{0} comments').format(str(post.comments))

		post.avatar = post.avatar or ""
		post.category = frappe.db.get_value('Blog Category', post.blog_category,
			['route', 'title'], as_dict=True)

		if post.avatar and (not "http:" in post.avatar and not "https:" in post.avatar) and not post.avatar.startswith("/"):
			post.avatar = "/" + post.avatar

	return posts
Example #14
0
	def set_metatags(self, context):
		context.metatags = {
			"name": context.title,
			"description": (context.description or context.main_section or "").replace("\n", " ")[:500]
		}

		image = find_first_image(context.main_section or "")
		if image:
			context.metatags["image"] = image
Example #15
0
 def set_metatags(self, context):
     context.metatags = {
         "name":
         self.meta_title or self.title,
         "description":
         self.meta_description,
         "image":
         self.meta_image or find_first_image(context.main_section or "")
     }
Example #16
0
    def get_context(self, context):
        # this is for double precaution. usually it wont reach this code if not published
        if not cint(self.published):
            raise Exception("This blog has not been published yet!")

        # temp fields
        context.full_name = get_fullname(self.owner)
        context.updated = global_date_format(self.published_on)

        if self.blogger:
            context.blogger_info = frappe.get_doc("Blogger",
                                                  self.blogger).as_dict()

        context.description = self.blog_intro or self.content[:140]

        context.metatags = {
            "name": self.title,
            "description": context.description,
        }

        if "<!-- markdown -->" in context.content:
            context.content = markdown(context.content)

        blog_settings = frappe.get_doc('Blog Settings', 'Blog Settings')

        context.enable_comments = blog_settings.enable_comments
        context.enable_blogger_info = blog_settings.enable_blogger_info

        image = find_first_image(self.content)
        if image:
            context.metatags["image"] = image

        context.comment_list = get_comment_list(self.doctype, self.name)
        if not context.comment_list:
            context.comment_text = _('No comments yet')
        else:
            if (len(context.comment_list)) == 1:
                context.comment_text = _('1 comment')
            else:
                context.comment_text = _('{0} comments').format(
                    len(context.comment_list))

        context.category = frappe.db.get_value("Blog Category",
                                               context.doc.blog_category,
                                               ["title", "route"],
                                               as_dict=1)
        context.parents = [{
            "name": _("Home"),
            "route": "/"
        }, {
            "name": "Blog",
            "route": "/blog"
        }, {
            "label": context.category.title,
            "route": context.category.route
        }]
Example #17
0
    def set_metatags(self, context):
        context.metatags = {
            "name":
            context.title,
            "description":
            context.description or (context.main_section or "")[:150]
        }

        image = find_first_image(context.main_section or "")
        if image:
            context.metatags["image"] = image
Example #18
0
    def get_context(self, context):
        # this is for double precaution. usually it wont reach this code if not published
        if not cint(self.published):
            raise Exception("This blog has not been published yet!")

        context.no_breadcrumbs = True

        # temp fields
        context.full_name = get_fullname(self.owner)
        context.updated = global_date_format(self.published_on)
        context.social_links = self.fetch_social_links_info()
        context.cta = self.fetch_cta()
        context.enable_cta = not self.hide_cta and frappe.db.get_single_value(
            "Blog Settings", "show_cta_in_blog", cache=True)

        if self.blogger:
            context.blogger_info = frappe.get_doc("Blogger",
                                                  self.blogger).as_dict()
            context.author = self.blogger

        context.content = get_html_content_based_on_type(
            self, 'content', self.content_type)

        #if meta description is not present, then blog intro or first 140 characters of the blog will be set as description
        context.description = self.meta_description or self.blog_intro or strip_html_tags(
            context.content[:140])

        context.metatags = {
            "name": self.meta_title,
            "description": context.description,
        }

        #if meta image is not present, then first image inside the blog will be set as the meta image
        image = find_first_image(context.content)
        context.metatags["image"] = self.meta_image or image or None

        self.load_comments(context)
        self.load_feedback(context)

        context.category = frappe.db.get_value("Blog Category",
                                               context.doc.blog_category,
                                               ["title", "route"],
                                               as_dict=1)
        context.parents = [{
            "name": _("Home"),
            "route": "/"
        }, {
            "name": "Blog",
            "route": "/blog"
        }, {
            "label": context.category.title,
            "route": context.category.route
        }]
        context.guest_allowed = True
Example #19
0
 def set_metatags(self, context):
     if not context.metatags:
         context.metatags = {
             "name":
             self.meta_title or self.title,
             "description":
             self.meta_description,
             "image":
             self.meta_image
             or find_first_image(context.main_section or ""),
             "og:type":
             "website"
         }
def execute():
	dt_list= ["Purchase Order Item","Supplier Quotation Item", "BOM", "BOM Explosion Item" , \
	"BOM Item", "Opportunity Item" , "Quotation Item" , "Sales Order Item" , "Delivery Note Item" , \
	"Material Request Item" , "Purchase Receipt Item" , "Stock Entry Detail"]
	for dt in dt_list:
		frappe.reload_doctype(dt)
		names = frappe.db.sql("""select name, description from `tab{0}` where description is not null""".format(dt),as_dict=1)
		for d in names:
			data = cstr(d.description)
			image_url = find_first_image(data)
			desc =  re.sub("\<img[^>]+\>", "", data)

			frappe.db.sql("""update `tab{0}` set description = %s, image = %s
				where name = %s """.format(dt), (desc, image_url, d.name))
Example #21
0
def get_context(context):
    homepage = frappe.get_doc('Homepage')

    for item in homepage.products:
        route = frappe.db.get_value('Item', item.item_code, 'route')
        if route:
            item.route = '/' + route

    homepage.title = homepage.title or homepage.company
    context.title = homepage.title
    context.homepage = homepage

    if homepage.hero_section_based_on == 'Homepage Section' and homepage.hero_section:
        homepage.hero_section_doc = frappe.get_doc('Homepage Section',
                                                   homepage.hero_section)

    if homepage.slideshow:
        doc = frappe.get_doc('Website Slideshow', homepage.slideshow)
        context.slideshow = homepage.slideshow
        context.slideshow_header = doc.header
        context.slides = doc.slideshow_items

    blogs = frappe.get_all(
        'Blog Post',
        fields=['title', 'blogger', 'blog_intro', 'route', 'content'],
        filters={'published': 1},
        order_by='modified desc',
        limit=3)

    for blog in blogs:
        blog.cover_image = find_first_image(blog.content)

    context.blogs = blogs

    # filter out homepage section which is used as hero section
    homepage_hero_section = homepage.hero_section_based_on == 'Homepage Section' and homepage.hero_section
    homepage_sections = frappe.get_all(
        'Homepage Section',
        filters=[['name', '!=', homepage_hero_section]]
        if homepage_hero_section else None,
        order_by='section_order asc')
    context.homepage_sections = [
        frappe.get_doc('Homepage Section', name) for name in homepage_sections
    ]

    context.metatags = context.metatags or frappe._dict({})
    context.metatags.image = homepage.hero_image or None
    context.metatags.description = homepage.description or None

    context.explore_link = '/all-products'
Example #22
0
	def get_context(self, context):
		# this is for double precaution. usually it wont reach this code if not published
		if not cint(self.published):
			raise Exception("This blog has not been published yet!")

		# temp fields
		context.full_name = get_fullname(self.owner)
		context.updated = global_date_format(self.published_on)

		if self.blogger:
			context.blogger_info = frappe.get_doc("Blogger", self.blogger).as_dict()

		context.description = self.blog_intro or self.content[:140]

		context.metatags = {
			"name": self.title,
			"description": context.description,
		}

		if "<!-- markdown -->" in context.content:
			context.content = markdown(context.content)

		image = find_first_image(self.content)
		if image:
			context.metatags["image"] = image

		context.comment_list = get_comment_list(self.doctype, self.name)
		if not context.comment_list:
			context.comment_text = _('No comments yet')
		else:
			if(len(context.comment_list)) == 1:
				context.comment_text = _('1 comment')
			else:
				context.comment_text = _('{0} comments').format(len(context.comment_list))

		context.category = frappe.db.get_value("Blog Category",
			context.doc.blog_category, ["title", "route"], as_dict=1)
		context.parents = [{"name": _("Home"), "route":"/"},
			{"name": "Blog", "route": "/blog"},
			{"label": context.category.title, "route":context.category.route}]
Example #23
0
def get_context(context):
    blog_post = context.doc

    # this is for double precaution. usually it wont reach this code if not published
    if not cint(blog_post.published):
        raise Exception, "This blog has not been published yet!"

    # temp fields
    blog_post.full_name = get_fullname(blog_post.owner)
    blog_post.updated = global_date_format(blog_post.published_on)

    if blog_post.blogger:
        blog_post.blogger_info = frappe.get_doc("Blogger",
                                                blog_post.blogger).as_dict()

    blog_post.description = blog_post.blog_intro or blog_post.content[:140]

    blog_post.metatags = {
        "name": blog_post.title,
        "description": blog_post.description,
    }

    image = find_first_image(blog_post.content)
    if image:
        blog_post.metatags["image"] = image

    blog_post.categories = frappe.db.sql_list(
        "select name from `tabBlog Category` order by name")

    blog_post.comment_list = frappe.db.sql("""\
		select comment, comment_by_fullname, creation
		from `tabComment` where comment_doctype="Blog Post"
		and comment_docname=%s order by creation""", (blog_post.name, ),
                                           as_dict=1) or []

    return blog_post.__dict__
def extract_image_and_description(data):
    image_url = find_first_image(data)
    desc = re.sub("\<img[^>]+\>", "", data)

    return image_url, desc
def get_blog_context(context):

    context["blog_fields"] = [
        "published_on", "blog_intro", "route", "title", "content", "name",
        "blog_category"
    ]
    context["blog_conditions"] = ""

    hooks = frappe.get_hooks("starter_theme_blog_context_before")
    for hook in hooks:
        frappe.call(hook, context)

    #posts = frappe.get_all("Blog Post", fields=context["blog_fields"], filters={"published": 1}, order_by="published_on desc, creation desc", limit=cint(context.get("theme_display_blog_length", 4)))

    query = """\
		select
			%(fields)s,
			ifnull(t1.blog_intro, t1.content) as intro,
			t2.full_name, t2.avatar, t1.blogger,
			(select count(name) from `tabCommunication`
			where
				communication_type='Comment'
				and comment_type='Comment'
				and reference_doctype='Blog Post'
				and reference_name=t1.name) as comments
		from `tabBlog Post` t1, `tabBlogger` t2
		where ifnull(t1.published,0)=1
			and t1.blogger = t2.name
			%(condition)s
		order by published_on desc, t1.creation desc
		limit %(start)s, %(page_len)s""" % {
        "start":
        0,
        "page_len":
        cint(context.get("theme_display_blog_length", 4)),
        "condition": (" and " + " and ".join(context["blog_conditions"]))
        if context.get("blog_conditions") else "",
        "fields":
        ",".join(["t1.%s" % field for field in context["blog_fields"]])
    }

    posts = frappe.db.sql(query, as_dict=1)

    for post in posts:
        post.cover_image = find_first_image(post.content)
        post.published = global_date_format(post.creation)
        post.content = strip_html_tags(post.content[:340])
        post.intro = post.blog_intro if post.blog_intro else post.content
        if not post.comments:
            post.comment_text = _('No comments yet')
        elif post.comments == 1:
            post.comment_text = _('1 comment')
        else:
            post.comment_text = _('{0} comments').format(str(post.comments))

        post.avatar = post.avatar or ""
        post.category = frappe.db.get_value('Blog Category',
                                            post.blog_category,
                                            ['route', 'title'],
                                            as_dict=True)

        if (not "http:" in post.avatar or "https:"
                in post.avatar) and not post.avatar.startswith("/"):
            post.avatar = "/" + post.avatar

    context["blog_posts"] = posts

    hooks = frappe.get_hooks("starter_theme_blog_context_after")
    for hook in hooks:
        frappe.call(hook, context)
def extract_image_and_description(data):
	image_url = find_first_image(data)
	desc = data
	for tag in ("img", "table", "tr", "td"):
		desc =  re.sub("\</*{0}[^>]*\>".format(tag), "", desc)
	return desc, image_url
Example #27
0
def get_blog_list(
	doctype, txt=None, filters=None, limit_start=0, limit_page_length=20, order_by=None
):
	conditions = []
	category = filters.blog_category or frappe.utils.escape_html(
		frappe.local.form_dict.blog_category or frappe.local.form_dict.category
	)
	if filters:
		if filters.blogger:
			conditions.append("t1.blogger=%s" % frappe.db.escape(filters.blogger))
	if category:
		conditions.append("t1.blog_category=%s" % frappe.db.escape(category))

	if txt:
		conditions.append(
			'(t1.content like {0} or t1.title like {0}")'.format(frappe.db.escape("%" + txt + "%"))
		)

	if conditions:
		frappe.local.no_cache = 1

	query = """\
		select
			t1.title, t1.name, t1.blog_category, t1.route, t1.published_on, t1.read_time,
				t1.published_on as creation,
				t1.read_time as read_time,
				t1.featured as featured,
				t1.meta_image as cover_image,
				t1.content as content,
				t1.content_type as content_type,
				t1.content_html as content_html,
				t1.content_md as content_md,
				ifnull(t1.blog_intro, t1.content) as intro,
				t2.full_name, t2.avatar, t1.blogger,
				(select count(name) from `tabComment`
					where
						comment_type='Comment'
						and reference_doctype='Blog Post'
						and reference_name=t1.name) as comments
		from `tabBlog Post` t1, `tabBlogger` t2
		where ifnull(t1.published,0)=1
		and t1.blogger = t2.name
		%(condition)s
		order by featured desc, published_on desc, name asc
		limit %(page_len)s OFFSET %(start)s""" % {
		"start": limit_start,
		"page_len": limit_page_length,
		"condition": (" and " + " and ".join(conditions)) if conditions else "",
	}

	posts = frappe.db.sql(query, as_dict=1)

	for post in posts:
		post.content = get_html_content_based_on_type(post, "content", post.content_type)
		if not post.cover_image:
			post.cover_image = find_first_image(post.content)
		post.published = global_date_format(post.creation)
		post.content = strip_html_tags(post.content)

		if not post.comments:
			post.comment_text = _("No comments yet")
		elif post.comments == 1:
			post.comment_text = _("1 comment")
		else:
			post.comment_text = _("{0} comments").format(str(post.comments))

		post.avatar = post.avatar or ""
		post.category = frappe.db.get_value(
			"Blog Category", post.blog_category, ["name", "route", "title"], as_dict=True
		)

		if (
			post.avatar
			and (not "http:" in post.avatar and not "https:" in post.avatar)
			and not post.avatar.startswith("/")
		):
			post.avatar = "/" + post.avatar

	return posts
def extract_image_and_description(data):
    image_url = find_first_image(data)
    desc = data
    for tag in ("img", "table", "tr", "td"):
        desc = re.sub("\</*{0}[^>]*\>".format(tag), "", desc)
    return desc, image_url
def extract_image_and_description(data):
	image_url = find_first_image(data)
	desc =  re.sub("\<img[^>]+\>", "", data)
	
	return image_url, desc