简体   繁体   English

使用来自服务器的数据自动提供 html 页面?

[英]Automatically serve html page with data from server?

I have a HTML page that I'd like to contain a list of other pages.我有一个 HTML 页面,我想包含其他页面的列表。 These other pages are stored in a particular directory on my server.这些其他页面存储在我服务器上的特定目录中。 What's the best way to have the server send the page containing the list with the up-to-date list of pages?让服务器发送包含最新页面列表的页面的最佳方式是什么? I'd like each item to be a link, if that's possible as well.如果可能的话,我希望每个项目都是一个链接。

to summarize for clarity:为清楚起见总结:

  1. I have some webpages in a directory on my server, let's call it /dir.我的服务器目录中有一些网页,我们称之为/dir.

  2. I have a page that's a list of the webpages in /dir that I need to keep up to date.我有一个页面,它是/dir中我需要保持最新的网页列表。 since files are added to /dir frequently, it wouldn't make sense to hard-code the links into the page every time I add a new page to /dir.由于经常将文件添加到/dir ,因此每次将新页面添加到/dir.

  3. I'm looking for a way to keep the list on the page up to date with links to all the files in /dir , ideally from the server.我正在寻找一种方法来使页面上的列表保持最新,其中包含指向/dir中所有文件的链接,最好是来自服务器。

I'm using a Node.js server with Express.我正在使用带有 Express 的 Node.js 服务器。

If your index html page is in the same directory as your list of pages, one way to create a hyperlink to the up-to-date list is to use this formula for each page:如果您的索引 html 页面与您的页面列表位于同一目录中,则创建指向最新列表的超链接的一种方法是对每个页面使用以下公式:

<a href="./newPageName.html"> This text will be hyperlinked </a>

"./" will tell your code to look for the file starting from the same directory location as your index html. “./”将告诉您的代码从与索引 html 相同的目录位置开始查找文件。


If the html file you want to link is in a folder within the index's directory location:如果您要链接的 html 文件位于索引目录位置的文件夹中:

<a href="./folderName/newPageName.html"> This text will be hyperlinked </a> 

If the file is in the same directory, but a different folder, "../" will send you outside of the current directory's folder.如果文件在同一目录中,但在不同的文件夹中,“../”会将您发送到当前目录的文件夹之外。 From there, you can navigate to where the file is stored.从那里,您可以导航到文件的存储位置。

<a href="../folderName/newPageName.html"> This text will be hyperlinked </a> 

Here is an example from my own code.这是我自己的代码中的一个示例。 I used an unorganized list, making each additional link a list item, as I found it, well, more 'organized'.我使用了一个无组织的列表,使每个附加链接成为一个列表项,因为我发现它,嗯,更“有组织”。 All of these files are stored within their own folders ("lab2" "lab3" "lab4" "lab5") within a parent directory "art101".所有这些文件都存储在父目录“art101”中自己的文件夹(“lab2”“lab3”“lab4”“lab5”)中。 Because my main index html (the one containing all these linked index.html files) is directly in "art101" (not in a folder within "art101"), I don't have to use "../" to navigate out to "art101".因为我的主要索引 html (包含所有这些链接索引的索引。html 文件)直接在“art101”中(而不是在“art101”中的文件夹中),我不必使用“../”导航到“艺术101”。

<ul id="labs">
  <li> <a href="lab2/index.html" target="_blank"> lab2 - html and css starter</a> </li>
  <li> <a href="lab3/index.html" target="_blank"> lab3 - file structure/transfer</a> </li>
  <li> <a href="lab4/index.html" target="_blank"> lab4 - problem solving </a> </li>
  <li> <a href="lab5/index.html" target="_blank"> lab5 - data types & variables</a> </li>
</ul>

I hope this makes sense/helps!我希望这有意义/有帮助!

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

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