简体   繁体   English

“操纵” html文件(服务器端),并将其内容插入html主页(*无* PHP)

[英]“Manipulate” html files (server-side) and insert their content in main html page (*without* PHP)

Context : I'm working on a site that runs on my university's server (IIS, not Apache), no way to use PHP. 上下文:我正在一个在我大学的服务器(IIS,而不是Apache)上运行的网站上工作,无法使用PHP。

I want the site to be so simple that people with very little HTML/CSS/js knowledge can put new content when I'll be done with it. 我希望网站如此简单,以至于只有很少的HTML / CSS / js知识的人可以在完成新内容后就添加新内容。 I'm a grad student in health sciences and I've learned HTML, CSS, etc. by myself since a few years (so I'm definitely not a pro), so pardon me if my question is a little naive. 我是健康科学专业的研究生,并且几年以来我一直独自学习HTML,CSS等(所以我绝对不是专业人士),所以请问我的问题是否有点天真。

I'd really need some script/tool that would allow me to : 我真的需要一些脚本/工具来允许我:

  • Get content from an external file (blog post) on the server (let's say a list of ".html" files located in a folder on the server, let's say the folder "/blog-posts/", containing a bunch of files named "jan-15.html", "feb-15.html", etc.) 从服务器上的外部文件(博客文章)中获取内容(假设位于服务器文件夹中的“ .html”文件列表,例如文件夹“ / blog-posts /”,其中包含一堆名为“ jan-15.html”,“ feb-15.html”等)
  • Pick the last 4 files (4 most recent) 选择最后4个文件(最近4个)
  • Insert this content at a precise point in a html file 将此内容精确插入HTML文件中
  • (Optional, but it would really be nice) Pull the date the file was last edited, put it in a string and insert said string before the blog post, in the home page (可选,但这的确不错)将文件的最后编辑日期拉出,将其放入字符串中,并在主页的博客文章之前插入所述字符串。

So : 因此:

  • Do anyone know if anything like this already exists ? 有人知道这样的东西是否已经存在吗?
  • If not, do you guys think it's possible with some js/jQuery to "manipulate" external files like that ? 如果不是,你们是否认为可以使用某些js / jQuery这样“操纵”外部文件?
  • If it's possible, any hints how :) ? 如果可能,任何提示如何:)?

Thanks a million times, I know I'm asking a lot, but I've been searching for a viable solution for this for the last few months... It's my first time writing here but I've been an avid reader since a very long time. 感谢百万次,我知道我要问的很多,但是最近几个月我一直在寻找一个可行的解决方案……这是我第一次在这里写作,但是自从很长时间。

Have a great day ! 祝你有美好的一天 !

You can store a simple blog configuration as a JSON object and update it as you add new posts. 您可以将简单的博客配置存储为JSON对象,并在添加新帖子时对其进行更新。 Let's say you have the files jan.html and feb.html in your blog-posts folder. 假设您的blog-posts文件夹中有jan.htmlfeb.html文件。

Now in the main folder, create a file content.json as follows this: 现在,在主文件夹中,创建文件content.json ,如下所示:

{
    "posts": [
        { "uri": "feb.html", "date": "2/12/15" },
        { "uri": "jan.html", "date": "1/3/15" }
    ]
}

Now you can get the blog content with AJAX requests from JavaScript. 现在,您可以使用来自JavaScript的AJAX请求来获取博客内容。 Example: 例:

 <script> function Init(posts) { var e = document.getElementById('content'); var s = ''; posts.forEach(function(post) { console.log(post.content); s += '<div><h2>Date: ' + post.date + '</h2><p>' + post.content + '</p></div>'; }); e.innerHTML = s; } function LoadContent(config) { var remain = config.posts.length; var posts = []; config.posts.forEach(function(post) { var req = new XMLHttpRequest(); req.open('GET', 'blog-posts/' + post.uri, true); req.onload = function() { remain--; posts.push({ content: req.responseText, date: post.date }); if(remain === 0) { Init(posts); } }; req.send(null); }); } function LoadConfig() { var req = new XMLHttpRequest(); req.open('GET', 'content.json', true); req.onload = function() { LoadContent(JSON.parse(req.responseText)); }; req.send(null); } window.addEventListener('load', LoadConfig); </script> <div id="content"></div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM