javascript - How to add additional functionalities? -
i got simple javascript based blog . first have @ below codes , ask question.
index.html have following codes in body
<script language="javascript" type="text/javascript" src="blog/config.js"> </script> <script language="javascript" type="text/javascript" src="blog/single.js"> </script> <script language="javascript" type="text/javascript" src="blog/posts.js"> </script>
config.js has
//this configuration file of blog system. //change these variables suit style , needs var head = "h2"; //the heading style, ex. h1, h2, ect. use "h2" rather "<h2>" var text = "text"; //the text style, style sheet, it's in <div> tag var divider = "<hr>"; //the division between posts var newer = "newer"; //the class link next newest page var older = "older"; //the class link next oldest page var pageclass = "page"; //the class text displays page number var dateclass = "date"; //the class date var pagesize = 4; //the number of posts on each page var navclass = nav; //the configuration navigation`
posts.js
var posts = 1; //add 1 after adding post. should equal id of newest post. initblog(posts); var id = 1; //make sure number 1 greater 1 below var date = "mm/dd/yyyy"; //the date of post var heading = "post 1"; //the title var entry = ""; //reset string //don't worry formatting , stuff that, system takes care of us. //vv entry vv entry += "<p>wow, post on page, if have many real posts, congratulations!</p>"; //^^ important part ^^ add_entry(id,date,heading,entry); //adds entry blog
single.js
var maxpost; function initblog(posts){ maxpost = posts; var address = window.location.search; if (address.substring(0, 1) == '?') { page = address.substring(1); } else{ window.location = "post.html?" + posts; } page = parseint(page); if (page > maxpost){ page = maxpost; } if (page < 1){ page = 1; } } function add_entry(id,date,heading,entry) { (i=page;i>page - 1;i--){ if (id == i){ var entrytext = ""; entrytext += "<div class=" + text + ">"; entrytext += "<" + head + ">"; entrytext += "<a name=" + id + "></a>"; entrytext += "<span class='date'>[" + date + "]</span> "; entrytext += heading; entrytext += "</" + head + ">"; entrytext += entry; entrytext += "</div>" + divider; document.write(entrytext); } } } function pages(){ entrytext = "" entrytext += "<table class=\"nav\"><tr>"; entrytext += "<td width=25% class = " + newer + "> "; if (page < maxpost){ entrytext += "<a href=javascript:prev()>newer posts </a>"; } entrytext += "</td><td width=50% class = " + pageclass + "><br><a href=javascript:newest()> index</a></td>"; entrytext += "<td width=25% class = " + older + "> "; if (page-1 > 0){ entrytext += "<a href=javascript:next()>older posts</a>"; } entrytext += "</td></table>"; entrytext += ""; document.write(entrytext); } function next(){ page = page - 1; if (page < 1) { page = page + 1; } window.location = "post.html?" + page; } function prev(){ page = page + 1; if (page > maxpost) { page = maxpost; } window.location = "post.html?" + page; } function newest(){ window.location = "index.html?" + maxpost; }
well , whole blog script . ain't added styles , may see comments on each lines simplicity. blog doesn't have options add title , meta description , keyword etc. due style of applying can nothing outside body tag.
1 . how add option take/load titles? 2 . how add feature load meta tag?
don't tell me edit , add titles on template (index.html) , because make no sense
as see heading block title of blog. need making more visible.
var entrytext = ""; entrytext += "<div class=" + text + ">"; entrytext += "<h1>" + heading + "</h1>"; entrytext += "<" + head + ">"; entrytext += "<a name=" + id + "></a>"; entrytext += "<span class='date'>[" + date + "]</span> "; entrytext += "</" + head + ">"; entrytext += entry; entrytext += "</div>" + divider; document.write(entrytext); document.title = heading;
this solve problem titles.
regarding meta tags, (actually standard) meta tags written betweeen <head> tags in html. make seo compilant need add them these tags. more detailed: http://www.w3schools.com/tags/tag_meta.asp
but, if code generated on client-side. there no meaning generate it, because search engine not parse on-fly generated meta tags. because it's executed on browser.
Comments
Post a Comment