New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open current file/subtree in local hugo server #109

Closed
titaniumbones opened this Issue Dec 18, 2017 · 5 comments

Comments

Projects
None yet
2 participants
@titaniumbones
Contributor

titaniumbones commented Dec 18, 2017

(wishlist issue! would attach a label indicatung that if I could!)

When I'm working in HTML, I notice I do a lot of browse-url-of-buffer. I think it would be cool to have something equivalent for ox-hugo, that opened the localhost:xxxx url of the current buffer or subtree via hugo server -sw HUGO_BASE_DIR. At least for simple default cases, it should be easy to generate most parts of the URL from HUGO_BASE_DIR + HUGO_SECTION + EXPORT_FILENAME. I bet I'm not alone in wanting something like this.

The main difficulties I see include:

  • the hugo server command doesn't seem to make the port accessible anywhere, even if you enable logging to a logfile
  • as a result, there's not foolproof way to tell whether hugo server is already running on the relevant directory

What do you think -- is this worth pursuing? And is it at all practical?

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Dec 18, 2017

So that I understand the question clearly, are you suggesting that ox-hugo starts hugo server for the current site if it's not already running?

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Dec 18, 2017

If so, that would fall outside of the scope of this Org exporter package, but it's certainly possible. I know of @EnigmaCurry who implemented a hugo-server-start function that you can find here. There's also the easy-hugo-preview function provided by the easy-hugo package (thanks to @masasam).

I just take the lazy option.. I have a tmux window full of panes running hugo server --navigateToChanged at different ports for few sites I work on in parallel. The --navigateToChanged option is the key. Then with my point in a valid hugo subtree, I just do C-c C-e H H, and that exact post live reloads in the browser (because I also have all those localhosts as pinned tabs in my browser, that I never close).

I hope I answered your concern correctly.

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Dec 18, 2017

there's not foolproof way to tell whether hugo server is already running on the relevant directory

You can only run hugo server specific to a site, and you can specify the port using -p (Example: hugo server --navigateToChanged -p 10600). If you keep a personal assignment of each site to a unique port number, there won't be any issue.. and the --navigateToChanged option will auto-live-reload the site to the exact folder/page you modified.

@titaniumbones

This comment has been minimized.

Contributor

titaniumbones commented Dec 18, 2017

I just take the lazy option.. I have a tmux window full of panes running hugo server --navigateToChanged at different ports for few sites I work on in parallel. The --navigateToChanged option is the key. Then with my point in a valid hugo subtree, I just do C-c C-e H H, and that exact post live reloads in the browser (because I also have all those localhosts as pinned tabs in my browser, that I never close).

Oh, that's sweet. I hadn't noticed that option, that's great. Those other links look really helpful too, thank you. Do you have a little script to start those tmux panes when necessary?

I've never used pinned tabs (!!) Now I see how crazy that is.

@kaushalmodi

This comment has been minimized.

Owner

kaushalmodi commented Dec 18, 2017

Do you have a little script to start those tmux panes when necessary?

I use tmuxp to restore my tmux session organization. Below is a snippet of that starts the hugo servers in a tmux window named hugo in a tmux session named servers (the srvh and ./srv are just convenience wrappers I use to pack --navigateToChanged, port number and other options).

# How to use this file:
#   tmuxp load /path/to/this/file/servers.yaml
# - Specifying the .yaml extension is optional
# - Specifying the path is optional if file is in ~/.tmuxp
#
#   tmuxp --help for full help.
session_name: servers
suppress_history: false
windows:
  - window_name: hugo
    start_directory: '~'
    layout: tiled
    panes:
      # Server for scripter.co
      - shell_command:
          - cd ~/hugo/kaushalmodi.gitlab.io
          - hugo server --buildDrafts --buildFuture --navigateToChanged -p 1313
      # Server for work blog
      - shell_command:
          - cd ~/hugo/work_blog
          - hugo server --buildDrafts --buildFuture --navigateToChanged -p 4444
      # Server for ox-hugo doc site
      - shell_command:
          - cd ~/e/elisp/ox-hugo/doc
          - hugo server --navigateToChanged -p 5554
      # Server for ox-hugo test site
      - shell_command:
          - cd ~/e/elisp/ox-hugo/test/site
          - hugo server --buildDrafts --buildFuture --navigateToChanged -p 5555
      # Server for 106 site
      - shell_command:
          - cd ~/hugo/106
          - hugo server --navigateToChanged -p 10600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment