如何添加额外的功能?

How to add additional functionalities?

我得到了一个基于 JavaScript 的简单博客。先看看下面的代码,我会问我的问题。

Index.html 在其 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 有

//This is the configuration file of the blog system.
//change these variables to suit your style and needs 
var head = "h2"; //the heading style, ex. h1, h2, ect. use "h2" rather than "<h2>"
var text = "text"; //the text style, from your style sheet, it's in a <div> tag
var divider = "<hr>"; //the division between posts
var newer = "newer"; //the class for the link to the next newest page
var older = "older"; //the class for the link to the next oldest page
var pageclass = "page"; //the class for the text that displays the page number
var dateclass = "date"; //the class for the date
var pagesize = 4; //the number of posts on each page
var navclass = nav; //the configuration for the navigation`

posts.js

var posts = 1; //add 1 to this after adding a post. should be equal to the id of the newest post.
initblog(posts);
var id = 1; //make sure that this number is one greater than the one below it
var date = "mm/dd/yyyy"; //The date of the post
var heading = "Post 1"; //The title
var entry = ""; //reset the string
//don't worry about formatting and stuff like that, the system takes care of it all for us.
//VV your entry VV
entry += "<p>Wow, this post is on another page, If you have this many real posts, congratulations!</p>";
//^^ The most important part ^^
add_entry(id,date,heading,entry); //adds the entry to the 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) {
for (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 + ">&nbsp";
if (page < maxpost){
entrytext += "<A HREF=javascript:prev()>Newer Posts </A>";
}
entrytext += "</td><td width=50% class = " + pageclass + "><br><A HREF=javascript:newest()> Back to Index</A></td>"; 
entrytext += "<td width=25% class = " + older + ">&nbsp";
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;
 }

好吧,这就是整个博客脚本。我没有添加样式,为简单起见,您可能会看到每一行的注释。 这个博客没有添加标题和元描述、关键字等的选项。由于应用的风格,它不能在 body 标签之外做任何事情。

1。如何为 take/load 个标题添加选项? 2.如何添加加载meta标签的功能?

不要告诉我在模板上编辑和添加标题 (index.HTML),因为那没有意义

如您所见,标题块用于博客的标题。您所需要的只是让它更显眼。

    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;

这将解决您关于标题的问题。

关于元标签,通常(实际上是标准的)元标签写在HTML中的标签之间。要使其符合 SEO 标准,您需要将它们添加到这些标签中。更详细:http://www.w3schools.com/tags/tag_meta.asp

但是,如果此代码是在 client-side 上生成的。生成它没有意义,因为搜索引擎不会解析 on-fly 生成的元标记。因为它是在浏览器上执行的。