[英]“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 : 我真的需要一些脚本/工具来允许我:
So : 因此:
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.html
和feb.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.