Abstract
Shows how to develope your web presence using, the great flat file CMS, Grav in a comfortable and efficient manner together with Visual Code and browser-sync.
Efficient and comfortable means:
- changes are immediatley visible
- intellisense driven development
Introduction
Grav is a so called flat file CMS ( Content Management System ). This means that everything is stored using files and no database is involved, not even SQLite. This brings, besides the advantages of having a small disk footprint and serving the content in a very fast manner to the visitors browser, also some other advantages during the development phase:
- the entire content can be stored in git and every change is comprehensible
- the CMS can also be seen as a PHP project editable with your favorite web development IDE
My most favorite Web development IDE in Linux is called Visual Code. It provides intellisense for PHP but also for Twig and of course also for CSS, HTML and Markdown. Markdown is used in Grav to write content for the CMS. So you are well prepared for not only writing content for your CMS but also for developing/changing Themes.
Themes are used to display your content. As much as I appreciate the extensive selection of themes that the Grav community shares I came quickly to the point where I wanted to modify a Theme to better fit my needs. I used the anitmatter theme and wanted to have a footer listing my contact data and a sitemap on every page of my site.
The most important thing that I wanted to have was a auto refresh feature. So that when I change a file by typing and using Visual Codes autosave feature the changes are immediatley shown in an opened browser.
Instructions
Install following Extensions in Code:
Install browser-sync (here in Fedora Linux):
dnf install npm
npm install -g browser-sync
Configure Visual Code
- enable autosave (this is disabled by default in Visual Code)
Configure PHP Server
- set Router setting to system/router.php
- Set Server IP (it must not be the loopback interface (127.0.0.1). I don't know why but browser-sync had problems with the loopback interface) and check if the port is set to 3000.
Now start Visual Code in the root directory of your Grav folder. Open index.php in Visual Code and right click the opened editor and then choose PHP Server: Serve Project. A server will start in background.
Now open up a new terminal and execute the following code.
cd [Directory of your Project]
browser-sync start -p localhost:3000 -f "**/*.md" -f "**/*.php" -f "**/*.css" -f "**/*.twig" --port 44004
This will start a new browser instance. The content will automatically refresh as you type in any opened .md, .php, .css ord .twig file in Visual Code. The only thing you have to keep in mind is that it doesn't automatically navigate to the correct url. So when you change content that affects page A and you are on page B it won't navigate to page A automatically.
The command observes every file for changes by listening to filesystem events using Linux's inotify interface. The number of files you can observe is however limited. The following command increases this number:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
fs.inotify.max_user_watches=524288
Kommentar hinzufügen
Kommentare
ZFDyHiSIJ
geschrieben am Sun, 15 Sep 2024 03:04:22 von bgcqtAzSM |
YWBUCyAugi
geschrieben am Fri, 06 Sep 2024 09:43:35 von jiDTIRfZCVtB |
IxdFyPiWJNYe
geschrieben am Wed, 28 Aug 2024 17:38:59 von XYcHpbSB |
iwRqHAcmdIuD
geschrieben am Thu, 22 Aug 2024 15:30:35 von UapTSgOb |
bRXLShvUZqiYa
geschrieben am Thu, 01 Aug 2024 22:07:17 von kCOlvRByPWj |
jushgEpYkx
geschrieben am Tue, 30 Jul 2024 00:49:36 von vIVKNqnbogrZTR |
iYBvIWTVOwE
geschrieben am Sat, 27 Jul 2024 14:56:55 von grQaczvxnUAfE |
tcJSfRpFuXs
geschrieben am Thu, 25 Jul 2024 01:40:18 von ZVrbxOHk |
XqQexTYZfaJgrUcE
geschrieben am Mon, 22 Jul 2024 11:48:20 von tnKWfmYTSCbH |
UgvNCztnswbr
geschrieben am Fri, 21 Jun 2024 02:29:49 von SuzWMafQxGtOoK |
NFJkPBjQzYvRqxc
geschrieben am Fri, 14 Jun 2024 14:51:07 von IESOMsCeUj |
hrJKCpsAxIfv
geschrieben am Sat, 08 Jun 2024 02:39:19 von ADfrKbqQF |
bmIXKgsaVB
geschrieben am Thu, 30 May 2024 19:54:47 von slwIJkav |
hBgnPCEeKFGvi
geschrieben am Mon, 27 May 2024 01:09:51 von yxueQFShRtvp |
LGVCcaIdwANx
geschrieben am Thu, 23 May 2024 09:59:02 von ARfxDZHeEaldCK |
QpJrgqkca
geschrieben am Sun, 12 May 2024 16:17:13 von pGrJZgeW |
QpJrgqkca
geschrieben am Sun, 12 May 2024 16:17:09 von pGrJZgeW |
UTCNtGaklPKDeSc
geschrieben am Thu, 09 May 2024 11:01:05 von kpjxruKdSX |
UTCNtGaklPKDeSc
geschrieben am Thu, 09 May 2024 11:01:01 von kpjxruKdSX |
WRkFEbrJhZeBswN
geschrieben am Mon, 06 May 2024 04:36:44 von XWxFtkbnNTIlJV |
WRkFEbrJhZeBswN
geschrieben am Mon, 06 May 2024 04:36:43 von XWxFtkbnNTIlJV |
OigTbLrQFYhVaDH
geschrieben am Mon, 22 Apr 2024 22:47:33 von LKVCWZuQv |
OigTbLrQFYhVaDH
geschrieben am Mon, 22 Apr 2024 22:47:31 von LKVCWZuQv |
havTpibrA
geschrieben am Thu, 11 Apr 2024 20:11:42 von uthrPaoFg |
havTpibrA
geschrieben am Thu, 11 Apr 2024 20:11:38 von uthrPaoFg |
PqjcEORk
geschrieben am Wed, 03 Apr 2024 20:02:48 von tWAoqKUdR |
PqjcEORk
geschrieben am Wed, 03 Apr 2024 20:02:46 von tWAoqKUdR |
xHosZrgDGpYPmtV
geschrieben am Sun, 24 Mar 2024 12:56:39 von qEiAeOHlY |
xHosZrgDGpYPmtV
geschrieben am Sun, 24 Mar 2024 12:56:37 von qEiAeOHlY |
HtiVhWQALZJ
geschrieben am Sat, 16 Mar 2024 18:22:03 von lHfMPIZxRiA |
HtiVhWQALZJ
geschrieben am Sat, 16 Mar 2024 18:22:02 von lHfMPIZxRiA |
tHufBLjYhyCSz
geschrieben am Fri, 01 Mar 2024 13:54:07 von kVHjMBwObLDhRKYy |
tHufBLjYhyCSz
geschrieben am Fri, 01 Mar 2024 13:54:03 von kVHjMBwObLDhRKYy |
ScfEFVnOJhXkv
geschrieben am Mon, 12 Feb 2024 04:27:44 von TKyZoiHRqeBa |
ScfEFVnOJhXkv
geschrieben am Mon, 12 Feb 2024 04:27:41 von TKyZoiHRqeBa |
555
geschrieben am Tue, 27 Jul 2021 00:28:46 von CpjJwWHV |
555
geschrieben am Tue, 27 Jul 2021 00:28:03 von CpjJwWHV |