Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


How best to implement the following web page design?
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

How best to implement the following web page design?

Hi Everyone,

As a preface, I'm old-school as far as web page design is concerned: HTML 4/5 + some modest CSS. So far nothing fancier than this, though I'm willing to learn.

My question concerns a fairly common and simple design, illustrated by the following page:

http://ftp.nluug.nl/

Basically, you display (i) the contents of a given text file in a directory followed by (ii) a listing of the contents of that directory. Now, (ii) alone is easy, but how to implement both (i) and (ii)?

If I look at the source code of the page given above, namely,

view-source:http://ftp.nluug.nl/

it looks like it was hand-coded to do exactly (i) and (ii), but my guess is that this is the output of some program, for otherwise it would seem to be a maintenance nightmare if there are many pages like this (see e.g. http://ftp.nluug.nl/NetBSD/ ). Or did they really hand-code this?

There are more sophisticated versions of the same design, for example,

https://ctan.org/tex-archive/macros/latex/required/amsmath

but in this case the corresponding source code,

view-source:https://ctan.org/tex-archive/macros/latex/required/amsmath

definitely doesn't appear to be hand-coded and uses JavaScript in a couple of places.

My own strategy would be to use an inline frame (iframe) for the display of the chosen text file, but then I would have to decide on how to display the file's contents. JavaScript? PHP? Something else?

If any of you have had to implement this design, any hints or advice would be much appreciated.

Comments

  • ChronicChronic Member
    edited September 2017

    You should be able to do this with mod_autoindex. Have a look at how they theme Apaxy.

    Also check readmename for mod_autoindex.

    Thanked by 1angstrom
  • @Chronic said:
    You should be able to do this with mod_autoindex. Have a look at how they theme Apaxy.

    Also check readmename for mod_autoindex.

    I hadn't thought about an Apache-specific strategy (I'm not running Apache on the server in question), and I guess that my preference would be to try to remain agnostic about the web server. At the same time, this may be a reason for preferring Apache. The link to Apaxy is also useful.

    By the way, at first glance, ReadmeName would append the file to the end of the index listing, whereas my preference would be to have the file appended to the beginning of the index listing. It appears that HeaderName would be more appropriate for this. I'll look into this.

    Still wondering about other strategies ...

  • angstrom said: My own strategy would be to use an inline frame (iframe) for the display of the chosen text file, but then I would have to decide on how to display the file's contents. JavaScript? PHP? Something else?

    If the text file were an HTML file, it would be displayed unproblematically, so I could consider simply making the chosen text file an HTML file. (Only a slight nuisance.)

  • I was bored. Took this as a small challenge. I've pasted a php script below.

    Run this script from the commandline with as parameter the directory to start with. For example
    php -f generate.php /some/dir

    NOTE: it will overwrite index.html files so be careful.

    You can change the html to your liking.

    Once you're happy with the output you can use incron to monitor for directory changes. Run this script when a directory changes and your index.html files will always be up-to-date.

    Enjoy.

    Thanked by 1angstrom
  • Sadly the captcha is unusable when posting 127 lines of code

  • mennomenno Member
    edited September 2017

    I'll try to post it in multiple comments.

    Edit: sorry. Posting it in smaller parts does not work either. Neither does the markdown support for code.

  • @menno said:
    Sadly the captcha is unusable when posting 127 lines of code

    Vanilla won't let you format it as code? Is it really that long?

  • No the code is not that long. Around 100 lines. If I paste the full code a CloudFlare captcha tries to intervene but does not display correctly so I cannot use. Happens in both Chrome and Firefox.

    And when I try to paste smaller blocks of code the formatting is lost. The markdown character ` for code does not work either. I am considered a hacker. No comment :)

  • Edit: sorry. Posting it in smaller parts does not work either. Neither does the markdown support for code.

    Pastebin it.

  • @menno said:
    I was bored. Took this as a small challenge. I've pasted a php script below.

    Run this script from the commandline with as parameter the directory to start with. For example
    php -f generate.php /some/dir

    NOTE: it will overwrite index.html files so be careful.

    You can change the html to your liking.

    Once you're happy with the output you can use incron to monitor for directory changes. Run this script when a directory changes and your index.html files will always be up-to-date.

    Enjoy.

    I appreciate your efforts and would be happy to try out your script if you manage to post a clean copy of it.

    However, my sense is that it may be more PHP-heavy than what I would like: if I had to use PHP, it would simply be to display a chosen text file.

  • Yup, just did that.
    https://pastebin.com/P4UNUD8Y

    Thanked by 2Aidan angstrom
  • angstrom said: However, my sense is that it may be more PHP-heavy than what I would like: if I had to use PHP, it would simply be to display a chosen text file.

    This is a command line script so no php is used at all for serving the files. It just generates the index files once and your web server does not need php. The webserver simply serves the index.html files. And when the directories change re-run the script on the command line. Automate that with a cron, or ideally with incron.

    Thanked by 1angstrom
  • angstromangstrom Moderator
    edited September 2017

    @menno said:

    angstrom said: However, my sense is that it may be more PHP-heavy than what I would like: if I had to use PHP, it would simply be to display a chosen text file.

    This is a command line script so no php is used at all for serving the files. It just generates the index files once and your web server does not need php. The webserver simply serves the index.html files. And when the directories change re-run the script on the command line. Automate that with a cron, or ideally with incron.

    Yes, I see, I've just tried it out.

    Again, I appreciate your efforts, but you see, the main issue for me is not how to get a directory listing, because every web server can do this well, but rather how to display a text file together with a directory listing. I'd prefer not to use PHP or another tool to generate a directory listing, because I can use the web server for this.

    Two constructive comments on generate.php:

    • It would be better to have it by default look at only the given directory and not at all subdirectories of the given directory as well (which is overkill if one is interested in listing only the given directory, plus all of those new index.html files aren't necessarily needed).

    • Overwriting index.html is risky: making a backup of the current index.html before overwriting it would be safer.

  • Thanked by 1angstrom
  • That's a useful link for an Apache-dependent strategy. Starting from the hint by @Chronic above, it's now clear to me that the basic design is very easy to achieve using Apache. The link that you give shows how to fine-tune the appearance of the page using Apache.

    At the moment, I'm still inclined to resist an Apache-dependent strategy, but then the most obvious alternative is to use PHP. I'm currently looking into a server-side PHP solution, so a bit different from what @menno proposed above.

  • @angstrom said:

    That's a useful link for an Apache-dependent strategy. Starting from the hint by @Chronic above, it's now clear to me that the basic design is very easy to achieve using Apache. The link that you give shows how to fine-tune the appearance of the page using Apache.

    At the moment, I'm still inclined to resist an Apache-dependent strategy, but then the most obvious alternative is to use PHP. I'm currently looking into a server-side PHP solution, so a bit different from what @menno proposed above.

    just trying to help others that may find this page via Google,

    Chronic's LINK for most new people to the web server thing, is total tech jargon,

    my like shows how to put that tech jargon to real use, in a simple way..

Sign In or Register to comment.